1

When I use the microsoft.office.interop.excel to create Excel file, I always call the quit command at the end. However, more than ever, if I look into the process list of Windows Task manager, I can clearly see that the process is still there and I end up with a bunch of those after a while.

I guess this isn't that much of a problem on normal case, but I would still like to prevent that from happening every time.

Is there any way to do this ?

I can't go on and kill all Excel process because some of them might really be application running and I can't really tell the difference between the two.

Thanks.

krock
  • 28,904
  • 13
  • 79
  • 85
David Brunelle
  • 6,528
  • 11
  • 64
  • 104
  • 3
    Probably asked already: http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects – NeverHopeless Nov 13 '12 at 19:41
  • You're right. I'll close it. – David Brunelle Nov 13 '12 at 19:49
  • I asked a similar question - http://stackoverflow.com/questions/12916137/best-way-to-release-excel-interop-com-object - Hope this helps. – John Bustos Nov 13 '12 at 20:37
  • You can refer to this article if it could help : http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects/158752#158752 – Ruchi Nov 16 '12 at 22:38
  • This article did help me : http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects/158752#158752 – Ruchi Nov 16 '12 at 22:39

1 Answers1

3

Notorious offender(automation)! To completely close the process you call Marshal.FinalReleaseComObject({com object}) for all Word and Excel objects.

OneFineDay
  • 9,004
  • 3
  • 26
  • 37
  • Does it still require me to enforce the "no 2 dot" rule ? – David Brunelle Nov 14 '12 at 13:05
  • This method is the same as calling ReleaseComObject in a loop til it = 0. One stop shopping! Open, use, Quit, Marshal.Final..... and you don't need GC.Collect. I have tested this extensively. – OneFineDay Nov 14 '12 at 16:50