Question

I am using Excel Interop. In the beginning of a method I got, I'm allocating a new instance of the application and at the end of it I'm trying to free it, but when I look at the TaskManager I can still see Excel open.

This is the code:

A class member: private Excel.Application _app;

The usage:

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

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

MethodApp can run several times and it opens instances at the same quantity as the number of times it's called. Why won't Excel close?

Was it helpful?

Solution

Try releasing any worksheets and workbooks used also in the order below:

Marshal.ReleaseComObject(_worksheet);
Marshal.ReleaseComObject(_workbook);
Marshal.ReleaseComObject(_app);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top