Word process not terminating

  • Thread starter Thread starter machine
  • Start date Start date
M

machine

I'm automating word form a c# windows application for spell checking
purposes. The problem is that sometimes the winword.exe process does
not terminate. Any clues why? I posted some code below.
/Martin
ArrayList arrPositions = new ArrayList();
ArrayList arrLengths = new ArrayList();
ArrayList[] arrList = new ArrayList[2];
int intPosition = 0;

Word.ApplicationClass objWord = null;
object junk = System.Reflection.Missing.Value;
try {
objWord = new Word.ApplicationClass();
string[] strArray = str.Trim().Split(new char[] {' '});
for(int i = 0; i < strArray.Length; i++) {
string strWord = strArray;
if(!objWord.CheckSpelling(strWord, ref junk, ref junk, ref junk,
ref junk, ref junk, ref junk, ref junk, ref junk, ref junk, ref junk,
ref junk, ref junk)) {
arrPositions.Add(intPosition);
arrLengths.Add(strWord.Length);
}

int n = strWord.Length + 1;
intPosition += n;
}
arrList[0] = arrPositions;
arrList[1] = arrLengths;
return arrList;
}
catch (Exception ex) {
throw ex;
}
finally {
if(objWord != null) {
objWord.Quit(ref junk, ref junk, ref junk);
objWord = null;
}
}
 
Martin,

You need to call Marshal.ReleaseCOMObject

Check out the following article:

317109 PRB: Office Application Does Not Quit After Automation from Visual
http://support.microsoft.com/?id=317109


Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
Thanks Bharat!

That helped a lot. It seems if I call my "spell check" method several
times, within a short time interval, the winword.exe remains after
trying to shut it down (I call GC.Collect() as the article suggested).
The problem is that I cannot see a pattern, it seems random. The
process shuts down more often than before, so it is improving!

/Martin
 
Back
Top