私の目標は、分析とデータベースのトレースに共有カレンダーを開くことです。Outlookのinteropがあまりにも多くのアイテムを開くとエラーが発生する
ポイントはアイテムを開くことができますが、数百回後には例外が発生します。 管理者(セキュリティ上の理由)は、同時公開されている項目の量を制限していることを説明します。
私はこれを理解することができますので、私は各項目を読んだ後に閉じようとしました。しかし、私はまだエラーが発生します。この問題は、ユーザーのプロパティを読み込んでいるときに表示されます。ここで
は私のプログラムのサンプルです:
Recipient recipient = mapiNamespace.CreateRecipient("John Doe");
if (recipient.Resolve())
{
CalendarFolder = mapiNamespace.GetSharedDefaultFolder(recipient, OlDefaultFolders.olFolderCalendar);
outlookCalendarItems = CalendarFolder.Items;
outlookCalendarItems.IncludeRecurrences = false;
}
else
{
Console.Write("Failed to open Calendar");
return;
}
foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{
Console.WriteLine(item.Subject + " -> " + item.Start.ToLongDateString()); //=> Ok, no problem
UserProperty up = item.UserProperties.Find("Test"); //=> Problem if too many items
if(up!= null)
{
Console.Write("UserProperty Value: " + up.Value);
}
((Microsoft.Office.Interop.Outlook._AppointmentItem)item).Close(OlInspectorClose.olDiscard); //=> Problem if too many items
Console.WriteLine();
}
Console.ReadKey();
適切項目を閉じる方法上の任意のアイデア?
System.Runtime.InteropServices.Marshal.ReleaseComObject(_calendar_item);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
あなたが触れるすべてのOutlookインスタンスでMarshal.ReleaseComObjectを呼び出す必要があります。それが0になるまでループ内で呼び出す。 – MethodMan
そうです、私は各アイテムのリリースを強制しなければなりませんでした。 System.Runtime.InteropServices.Marshal.ReleaseComObject(item);ありがとう! –
すごく嬉しいことに、私が手伝ってくれたことをうれしく思っています.COMオブジェクトやInteropを扱うときは、オブジェクトをマーシャリング、呼び出し、解放するときに違います。私はデルのCOMをたくさん使っています。約15年前にチャンスを取ったときに投票する – MethodMan