简体   繁体   中英

Excel Interop instances won't close

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?

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

Marshal.ReleaseComObject(_worksheet);
Marshal.ReleaseComObject(_workbook);
Marshal.ReleaseComObject(_app);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM