Alternatively, you can kill the Excel instance. I have to maintain an application which makes heavy use of Excel. I have written a wrapper for the base functionality. In the
Dispose()
method of the wrapper, I use the following code to ensure Excel will be released:
mExcelApp.Quit();
Process[] processes = Process.GetProcessesByName("Excel");
for (int i = 0; i < processes.Length;i++ )
{
if(processes[i].Id == mProcessId)
{
processes[i].Kill();
break;
}
}
This will perfectly release the Excel instance I use with one exception. If I'm in Debug mode and cancel the application in the debugger, the instance is kept alive.
Regards
Klaus