문제

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top