system.runtime.interopservices.comexception..服务器管理员限制了可以同时打开的项目数…
在microsoft.office.interop.outlook.\u appointmentitem.get\u 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?
最佳答案
完成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)
Next