3

I am developing an Outlook add-in, the primary purpose of which is to collect meeting data. Naturally this means I need to loop through some meetings! So I do that and start getting some property values out of the meeting objects. At this point things start getting slow. According to VS's Performance Profiler, getting a reference to AppointmentItem.ResponseStatus is taking up 20% of processing power. Here's some code:

//Setting meetingItem in this loop accounts for 38% of CPU usage.
for (Outlook.AppointmentItem meetingItem; (meetingItem = calendarItems.GetNext() as Outlook.AppointmentItem) != null;)
{
    //I do this instead of using Outlook.Items.Restrict() because Restrict() was EVEN SLOWER but this line is still 27% of CPU usage.
    if (DateTime.Compare(meetingItem.Start, start) <= 0 || DateTime.Compare(end, meetingItem.Start) <= 0)
    {
        Marshal.ReleaseComObject(meetingItem);
        meetingItem = null;
        continue;
    }

    MeetingData data = new MeetingData();

    data.Subject = meetingItem.Subject; // This line is fine for some reason. Maybe because it's a string?

    Outlook.OlMeetingStatus meetingStatus = meetingItem.MeetingStatus; // As is this one
    Outlook.OlResponseStatus responseStatus = meetingItem.ResponseStatus; // 20%

    //After this point we continue harvesting data but with no more speed issues getting properties.
}

Some additional info:

  • The Performance Profiler lists all of the slow items as calls to a function called dynamicClass.IL_STUB_CLRtoCOM
  • I have tried several other methods for the for loop including a foreach on the Recipients object, a for loop using Recipients.Count, and using a while loop. The current for loop performed best (technically the while did, but the for is preferable for other reasons).
  • I was originally using Outlook.Items.Restrict() to limit the search range between start and end but this was even slower.

I just need some help getting rid of these bottlenecks as these are really holding up the speed of the add-in.

tupto
  • 135
  • 2
  • 6

0 Answers0