C#的MSOffice互操作Word将不能杀死WINWORD.EXE [英] c# MSOffice Interop Word will not kill winword.exe
问题描述
我正在写需要的MSWord文档解析器的应用程序。
I'm writing an application that needed a MSWord document parser.
我使用Microsoft.Office.Interop.Word.Document来提取文本文件,但即使我使用doc.Close()的文件,从任务管理器,我可以看到,WINWORD.EXE没有被杀死,并分析它吃了一些资源,很多夫妇数十个文件之后。
I'm using Microsoft.Office.Interop.Word.Document to extract the texts from the documents, but even if i use doc.Close() the document, from taskManager i can see that winword.exe are not killed, and after parsing a couple dozens documents it eats up some much resources.
是close()这个方法不对?
is close() the wrong method?
请帮助我,指出我如何正确地终止这些进程朝着正确的方向。 =)
please help me and point me to the right direction on how to terminate these processes properly. =)
~~~更新~~~
感谢所有帮助。我用的是app.quit(),也跑了一个循环,检查进程,问题就解决了! =)
Thanks for all the help. I use the app.quit() and also ran a loop that checks for the process and problem solved! =)
推荐答案
你打电话的Application.Quit ,还因为你正在做的互操作可能值得释放的 RCW包装
Are you calling Application.Quit , additionally since you're doing Interop it may be worthwhile to release the RCW wrapper.
所以基本上是这样的:
yourWordAppObject.Quit();
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(yourWordAppObject);
请注意,一些人使用:的 ReleaseComObject的但也有一些的潜在的隐患
Note some folks use: ReleaseComObject but there are some potential pitfalls
这篇关于C#的MSOffice互操作Word将不能杀死WINWORD.EXE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!