Excel Interop exams will not close

I am using Excel Interop. At the beginning of the method I received, I highlight a new instance of the application, and at the end of it I try to free it, but when I look at the TaskManager, I still see that Excel is open.

This is the code:

Class Member: private Excel.Application _app;

Using:

 public void MethodApp()
{
  _app = new Excel.Application();
  ....
  ....
  FreeApplicationResources();
}

private void FreeApplicationResources()
{
  _app.Quit();
  Marshal.ReleaseComObject(_app);
}

MethodApp can run several times and open instances in the same amount as the number of times it called. Why won't Excel close?

+4
source share
1 answer

Try to free any worksheets and books that are also used in the following order:

Marshal.ReleaseComObject(_worksheet);
Marshal.ReleaseComObject(_workbook);
Marshal.ReleaseComObject(_app);
+1
source

All Articles