KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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 properly closing and releasing the objects . 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 template ) that the process is left running. Here is a simple example which reproduces the problem: 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) <> 0) End While doc = Nothing While (Marshal.ReleaseComObject(documents) <> 0) End While documents = Nothing word.Quit() While (Marshal.ReleaseComObject(word) <> 0) End While word = Nothing GC.Collect() 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 :) Update: I tried GC.Collect at the end of the disposal step but still no luck. Update 2: I've narrowed the problem down to the use of custom templates. When I invoke Documents.Add(.
Tags (comma-separated)
Save Edits
Cancel