Excel Application Process Does Not Die (my problem solved)

R

Ron

I have noticed a bunch of posts regarding the use of the Excel COM object
regarding the Excel process never dies. I noticed them because I also had
this problem.

I was ReleasingComObject from Marshal on all Excel Sheets, WorkBooks, And
Apps. ** while (Marshal.ReleaseComObject(myobj) > 0); **
I did App.Quit()
I Closed al work books and set
I set all objects to null.

Still the process ran....

My app is a console app that loops a list of clients and creates and saves
some excel docs. During testing, at the very end of the app I put a
Console.ReadLine() because any exceptions were written out to the Console
and pasing by ReadLin() I could read them with out the app closing.


I removed the ReadLine() and now when the app runs the Excel process closes.
NOTE: Before even when I manually closed the App the process still ran....


So, if anyone has a similar problem, mabey this will help...

Ron
 
N

Nicholas Paldino [.NET/C# MVP]

Ron,

Because the Excel object model contains circular references, reference
counts tend to not be decremented to zero. This causes a big problem in
..NET, where there is no automatic decrement of a reference count upon
release.

If you have excessive calls to COM components that increment reference
counts, then your best bet would be to make sure that all variables that
reference COM components are set to null, then call a the static Collect
method on the GC class (which will force a decrement of the reference count
if the managed representation of the COM object is unreachable). Then, call
Quit (if desired), and you should see the process dissappear.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top