View Single Post
  #10   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Cindy M -WordMVP- Cindy M  -WordMVP- is offline
external usenet poster
 
Posts: 370
Default C# MailMerge from Excel

Hi ?B?Y2hyaXM=?=,

After the merge is done I still have WINWORD.EXE running under aspnet. I
know that GC is supposed to take care of that, but I have it in memory for a
long period of time. I tried to release them like this:

// Unload objects from the memory
System.Runtime.InteropServices.Marshal.ReleaseComO bject (wrdMailMerge);
System.Runtime.InteropServices.Marshal.ReleaseComO bject (oWordApp);
System.Runtime.InteropServices.Marshal.ReleaseComO bject (oWordDoc);

or like this:

wrdMailMerge = null;
oWordDoc = null;
oWordApp = null;

but none of those ways worked. any tricks?

Most "deterministic" method: Release the mailmerge and doc objects, as you do
above, by setting them to null. Now force GarbageCollection:
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
//Yes, you do it twice

Now, quit the application as Peter suggests (note that in C# you must pass a
ref obj parameter; you can pass "missing"), then perform the garbage
collection again.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)