[英]Microsoft.Office.Interop.Outlook Release Memory
I try to read some outlook msg files with Microsoft.Office.Interop.Outlook Dll. 我尝试使用Microsoft.Office.Interop.Outlook Dll读取一些Outlook msg文件。 I know Outlook must be installed on machine. 我知道必须在计算机上安装Outlook。
I use this code to read the msg file. 我使用此代码读取msg文件。 This works fine. 这很好。
Microsoft.Office.Interop.Outlook._Application app = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook._Application应用=新的Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem fld = (Microsoft.Office.Interop.Outlook.MailItem)app.Session.OpenSharedItem(filename); Microsoft.Office.Interop.Outlook.MailItem fld =(Microsoft.Office.Interop.Outlook.MailItem)app.Session.OpenSharedItem(filename);
But if I open the same msg-file an exception is thrown, becouse the file is already opened. 但是,如果我打开相同的msg文件,则会引发异常,因为该文件已打开。 I think the gc is not clearing the objects. 我认为gc不会清除对象。
How can I release the objects? 如何释放对象?
Probably you solved your problem nowadays, but you could try this: 也许您现在已经解决了问题,但是您可以尝试以下方法:
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(mailItem) != 0) { }
mailItem = null;
GC.Collect();
GC.WaitForPendingFinalizers();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.