title: WinWord.exe won't quit after calling Word.Documents.Add - Word .NET Interop
body: <p>I'm running into the classic scenario where, when creating Word COM objects in .NET (via the Microsoft.Office.Interop.Word assembly), the WinWord process won't exit even though I'm <a href="http://www.xtremevbtalk.com/showthread.php?p=1326018" rel="noreferrer">properly closing and releasing the objects</a>.</p>
  
  <p>I've narrowed it down to the use of the Word.Documents.Add() method.  I can work with Word in other ways without a problem (opening documents, modifying contents, etc) and WinWord.exe quits when I tell it to.  It's once I use the Add() method (and only when adding a <em>template</em>) that the process is left running.</p>
  
  <p>Here is a simple example which reproduces the problem:</p>
  
  <pre><code>Dim word As New Word.Application()
  word.Visible = False
  
  Dim documents As Word.Documents = word.Documents
  Dim doc As Word.Document = documents.Add(Template:=CObj(templatePath), NewTemplate:=False, DocumentType:=Word.WdNewDocumentType.wdNewBlankDocument, Visible:=False)
  
  '' dispose objects
  doc.Close()
  While (Marshal.ReleaseComObject(doc) &lt;&gt; 0)
  End While
  doc = Nothing
  
  While (Marshal.ReleaseComObject(documents) &lt;&gt; 0)
  End While
  documents = Nothing
  
  word.Quit()
  While (Marshal.ReleaseComObject(word) &lt;&gt; 0)
  End While
  word = Nothing
  
  GC.Collect()
  </code></pre>
  
  <p>As you can see I'm creating and disposing the objects properly, even taking the extra step to loop Marsha.ReleaseComObject until it returns the proper code.  Working with the Word objects is fine in other regards, it's just that pesky Documents.Add that is causing me grief.  Is there another object that gets created in this process that I need to reference and dispose of?  Is there another disposal step I need to follow?  Something else?  Your help is much appreciated :)</p>
  
  <p><code>Update:</code> I tried GC.Collect at the end of the disposal step but still no luck.</p>
  
  <p><code>Update 2:</code>  I've narrowed the problem down to the use of custom templates.  When I invoke Documents.Add(...) I specify a custom template for the new document.  If I don't do this and instead invoke Add() with no parameters, then the problem does not happen.</p>