【发布时间】:2016-08-22 19:19:10
【问题描述】:
小问题:outlook项目使用后如何正确关闭?
代码重现问题:
Dim olApp As New Microsoft.Office.Interop.Outlook.Application
Dim olSelection As Microsoft.Office.Interop.Outlook.Selection = olApp.ActiveExplorer.Selection
For i As Integer = 1 To olSelection.Count 'Outlook starts counting at 1
Dim olItem As Object = olSelection(i)
Dim sSubject As String = olItem.Subject
olItem.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard)
Runtime.InteropServices.Marshal.ReleaseComObject(olItem)
Next
说明:
可以将 Outlook 项目(MailItem、DocumentItem、PostItem,基本上是任何项目)复制到我的应用程序中。为此,我遍历了活动 Outlook 窗口的选定项目。
It works fine, but when more than 250 (it might be a different number depending on configuration) items are selected, a COMExeption is thrown:
Microsoft.VisualBasic.dll 中出现“System.Runtime.InteropServices.COMException”类型的未处理异常
附加信息:您的服务器管理员限制了您可以同时打开的项目数量。尝试关闭您已打开的邮件或从您正在撰写的未发送邮件中删除附件和图像。
当我不再需要它们时,我试图关闭它们,但它似乎没有任何作用。
关于同一错误的其他问题
我知道this 其他关于相同错误的问题,但我已经遵循前两个答案的建议,第三个接受(也是最后一个)答案不适合我的上下文
【问题讨论】:
-
你检查过this answer 吗?总之,在
ReleaseComObject()之后,将olItem的引用设置为Nothing。 -
@SuperPeanut 感谢您的回复,但在
ReleaseComObject之后添加olItem = Nothing并没有帮助
标签: .net vb.net outlook outlook-2010 comexception