获取Outlook.AppointmentItem的属性非常慢
问题描述:
我正在开发一个Outlook加载项,其主要目的是收集会议数据。当然这意味着我需要循环一些会议!所以我这样做,并开始从会议对象中获取一些属性值。此时事情开始变慢。根据VS的性能分析器,获得对AppointmentItem.ResponseStatus
的引用占用了20%的处理能力。下面是一些代码:获取Outlook.AppointmentItem的属性非常慢
//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
- 我曾尝试在for循环其他几种方法包括收件人对象的foreach,使用Recipients.Count的for循环以及使用while循环。目前的循环表现最好(技术上来说,尽管如此,但for是因为其他原因而优选的)。
- 我最初使用Outlook.Items.Restrict()来限制
start
和end
之间的搜索范围,但这个速度更慢。
我只是需要一些帮助摆脱这些瓶颈,因为这些确实阻碍了加载项的速度。
你是否循环遍历文件夹中的所有项目?请使用限制。 –