c# MSOffice Interop Word will not kill winword.exe

前端 未结 5 1567
野趣味
野趣味 2021-01-04 11:04

I\'m writing an application that needed a MSWord document parser.

I\'m using Microsoft.Office.Interop.Word.Document to extract the texts from the documents, but even

相关标签:
5条回答
  • 2021-01-04 11:38

    After performing the app.Quit(), you must do app = null; From my experiences, this will prevent leftover processes from hanging around. Just be sure to do the app.Quit() and app = null in your exception handler as well.

    0 讨论(0)
  • 2021-01-04 11:38

    I am thinking close just handles the document open inside word. Remember you can have more than 1 word document open with 1 application. You may want to try either a dispose method, or look at the word objects quit/exit methods (can't remember its been a while).

    0 讨论(0)
  • 2021-01-04 11:43

    If you want to end the process you need to call Quit on the Application object - see http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.applicationclass.quit%28v=office.14%29.aspx

    0 讨论(0)
  • 2021-01-04 11:45

    Are you calling Application.Quit , additionally since you're doing Interop it may be worthwhile to release the RCW wrapper.

    So basically something like:

    yourWordAppObject.Quit();
    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(yourWordAppObject);
    

    Note some folks use: ReleaseComObject but there are some potential pitfalls

    0 讨论(0)
  • 2021-01-04 11:51

    You must quit the application instance using app.quit(). Document.close() will just close the document. I also suggest setting app.visible = true when you're done processing so your user can close it themselves if all else fails.

    0 讨论(0)
提交回复
热议问题