获取Outlook.AppointmentItem的属性非常慢

时间:2017-08-04 13:54:08

标签: c# outlook com vsto

我正在开发一个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.
}

其他一些信息:

  • Performance Profiler将所有慢速项目列为对名为dynamicClass.IL_STUB_CLRtoCOM
  • 的函数的调用
  • 我为for循环尝试了其他几种方法,包括Recipients对象的foreach,使用Recipients.Count的for循环,以及使用while循环。当前的for循环表现最好(技术上虽然有,但是出于其他原因,for for是优选的)。
  • 我最初使用Outlook.Items.Restrict()来限制startend之间的搜索范围,但这甚至更慢。

我只是需要一些帮助来摆脱这些瓶颈,因为它们确实阻碍了加载项的速度。

0 个答案:

没有答案