locked
Getting Excel.Application object to clean up properly RRS feed

  • Question


  • It seems that lots and lots of people seem to have trouble getting an excel process to clean up properly, when creating an instance of Excel.Application in code.  The standard answer seems to be to always be sure and call Marshal.ReleaseComObject for each and every single com object instantiated during the life of the application instance,  then call GC.Finalize and GC.WaitForPendingFinalizers

    Now here's my experience, based on using C#, .NET 3.5 SP1 and excel 2007:

    1) I don't need to worry about the ReleaseComObject calls at all.  Simply calling GC.Finalize at the right time and in the right place cleans up everything.

    2) Except, if I access the Application's AddIns collection.  If I do that, then nothing I do - including calling ReleaseComObject setting to null, GC.Finalize, lather, rinse, repeate...   None of that works.     In fact, even once my application exits, the excel process remains.   Even if I do no cleanup at all, the excel process exits when my app exits.  Except when I access the AddIns collection.

    So my question is this - what is different about the AddIns collection from the others (workbooks, worksheets, etc..)?  Accessing all of these other properties and doing other stuff to the workbook behaves nicely when the GC runs.

    Are there other collections or objects such as AddIns that cause this problem?


    Thanks.

    Roger


    roger reynolds
    Monday, August 17, 2009 6:00 PM

Answers