Domanda

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?

È stato utile?

Soluzione

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

Marshal.ReleaseComObject(_worksheet);
Marshal.ReleaseComObject(_workbook);
Marshal.ReleaseComObject(_app);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top