我正在开发一个Outlook加载项,其主要目的是收集会议数据。当然,这意味着我需要循环一些会议!所以我这样做并开始从会议对象中获取一些属性值。在这一点上,事情开始变得缓慢。根据VS的性能分析器,获得AppointmentItem.ResponseStatus
的引用占用了20%的处理能力。这是一些代码:
//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.
}
其他一些信息:
dynamicClass.IL_STUB_CLRtoCOM
start
和end
之间的搜索范围,但这甚至更慢。我只是需要一些帮助来摆脱这些瓶颈,因为它们确实阻碍了加载项的速度。