首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Outlook COMException

Outlook COMException
EN

Stack Overflow用户
提问于 2012-11-07 22:32:32
回答 3查看 1.5K关注 0票数 4

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

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

代码语言:javascript
复制
        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 ;
                    }
                }
            }
        }

也许是它的appointment.UserProperties.Find("myInformation")导致了COMException?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-04-02 15:22:34

我已经找到了解决这个问题的办法。这是没有必要使用Find,因为Restrict使我需要的。

代码语言:javascript
复制
...
string filter = string.Format("[myInformation] = '{0}'", myInformation);
var calendarItems = calendar.Items.Restrict(filter);
...
票数 1
EN

Stack Overflow用户

发布于 2013-04-02 22:07:04

您需要确保在使用完Outlook项后立即使用Marshal.ReleaseComObject()释放它们,而不是等待垃圾收集器开始工作。

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

票数 3
EN

Stack Overflow用户

发布于 2013-05-23 22:52:49

完成Outlook邮件项目后,将其关闭,然后释放它

代码语言:javascript
复制
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
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13271829

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档