4

System.Runtime.InteropServices.COMException ..您的服务器管理员限制了您可以同时打开的项目数量...

在 Microsoft.Office.Interop.Outlook._AppointmentItem.get_UserProperties()

        var calendar = outlookApplication.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderCalendar);

        if (calendar == null || calendar.Items == null)
        {
            return null;
        }

        var calendarItems = calendar.Items;

        if (calendarItems != null && calendarItems.Count > 0)
        {
            // Dont convert to LINQ or foreach please -> may cause Outlook memory leaks. 
            for (int counter = 1; counter <= calendarItems.Count; counter++)
            {
                var appointment = calendarItems[counter] as AppointmentItem;

                if (appointment != null)
                {
                    var userProperty = appointment.UserProperties.Find("myInformation");

                    if (userProperty != null && userProperty.Value == myValue)
                    {
                        return appointment ;
                    }
                }
            }
        }

也许它的约会.UserProperties.Find("myInformation") 导致 COMException?

4

3 回答 3

3

您需要确保在使用完 Outlook 项目后立即发布它们,Marshal.ReleaseComObject()而不是等待垃圾收集器启动。

您还需要避免使用多个点表示法,以确保您不会获得包含中间结果且无法显式引用和释放的隐式变量(由编译器创建)。

于 2013-04-02T14:07:04.033 回答
3

完成 Outlook Mailitem 后关闭它然后释放它

For Each item As Outlook.MailItem In oFolder.Items
  '<process item code>

  'Close the item
    'SaveMode Values
    'olDiscard  = 1
    'olPromptForSave = 2
    'olSave = 0
  item.Close(1)

  'Release item
  Marshal.ReleaseComObject(item)
Next
于 2013-05-23T14:52:49.227 回答
1

我已经找到了解决方案。没有必要使用Find原因Restrict来制作我需要的东西。

...
string filter = string.Format("[myInformation] = '{0}'", myInformation);
var calendarItems = calendar.Items.Restrict(filter);
...
于 2013-04-02T07:22:34.423 回答