0

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

Harry
  • 2,429
  • 4
  • 21
  • 26
  • Keep your taskmanager open in the background and kill the processes manually from time to time. That's what I do. – Scoregraphic Jul 31 '14 at 09:12
  • Please Refer the following URLs http://stackoverflow.com/questions/15537713/c-sharp-proper-way-to-close-multiple-excel-objects-with-excel-process-destroyed http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects/158752#158752 – Gehan Fernando Jul 31 '14 at 09:17
  • Please Refer Following URLs http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects/158752#158752 – Gehan Fernando Jul 31 '14 at 09:18

0 Answers0