I'm using Microsoft.Office.Interop.Excel.Application
to load in an Excel file and read various sheets and whatnot.
As far as I understand, the correct way to close everything is to do:
Application excel = new Application();
Workbook wb = excel.Workbooks.Open(filename);
// do stuff with file
excel.Workbooks.Close();
excel.Quit();
The problem is, during debugging my application will throw exceptions or I might just halt the debugger manually. By the end of the day I've got loads of excel.exe
processes running and I get a "File is available" dialogue window appearing for each one.
How can I close the excel application properly, despite an exception or debugger halt? Or perhaps there's a different angle I can take, and just run a separate program, at the end of the day, which searches for all Excel instances and closes them.
Notes: This is a WPF project using Visual Studio 2012