Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# MSOffice Interop Word will not kill winword.exe

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 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.

is close() the wrong method?

please help me and point me to the right direction on how to terminate these processes properly. =)

~~~update~~~

Thanks for all the help. I use the app.quit() and also ran a loop that checks for the process and problem solved! =)

like image 388
Krispy Avatar asked Aug 15 '11 20:08

Krispy


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.


2 Answers

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

like image 118
Ta01 Avatar answered Sep 19 '22 17:09

Ta01


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.

like image 31
MGZero Avatar answered Sep 22 '22 17:09

MGZero