System.Runtime.InteropServices.COMException ..Your服务器管理员已限制您可以同时打开的项目数...
在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 ;
}
}
}
}也许是它的appointment.UserProperties.Find("myInformation")导致了COMException?
发布于 2013-04-02 15:22:34
我已经找到了解决这个问题的办法。这是没有必要使用Find,因为Restrict使我需要的。
...
string filter = string.Format("[myInformation] = '{0}'", myInformation);
var calendarItems = calendar.Items.Restrict(filter);
...发布于 2013-04-02 22:07:04
您需要确保在使用完Outlook项后立即使用Marshal.ReleaseComObject()释放它们,而不是等待垃圾收集器开始工作。
您还需要避免使用多点表示法,以确保不会得到包含中间结果且不能显式引用和释放的隐式变量(由编译器创建)。
发布于 2013-05-23 22:52:49
完成Outlook邮件项目后,将其关闭,然后释放它
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)
Nexthttps://stackoverflow.com/questions/13271829
复制相似问题