2

I am open and close an excel book fro mC# like this

Microsoft.Office.Interop.Excel.Application oXL = null;
Microsoft.Office.Interop.Excel.Workbook excelWorkbook  = null;

try
{

    excelWorkbook = oXL.Workbooks.Open(MyFile,
                0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "",
                true, false, 0, true, false, false);

    .....
    ....
    ....

    excelWorkbook.Save();
    excelWorkbook.Close(Microsoft.Office.Interop.Excel.XlSaveAction.xlSaveChanges, Type.Missing, Type.Missing);
    oXL.Quit();
    excelWorkbook = null;
    oXL = null;

}
catch { }

But there is stil lan EXCEL.EXE process left running in the task list, why ? how do I "kill" everything about excel when I am done ? Is it not enough with ".Quit()" and put the reference to null ?

or is there some magic reference left in the C# heap somewhere that have not been dereferenced ?

/Stefan

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Stefan Olsson
  • 617
  • 3
  • 16
  • 32
  • Duplicate question. Check this http://stackoverflow.com/questions/2685159/unable-to-diligently-close-the-excel-process-running-in-memory and http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects-in-c – Sandeep G B Sep 14 '11 at 11:17
  • http://stackoverflow.com/questions/2685159/unable-to-diligently-close-the-excel-process-running-in-memory might be helpful for you – 62071072SP Sep 14 '11 at 11:18
  • Please stop turning question titles into a string of meaningless tags, tags belong into the tags section, the question title should be an actual question which describes the problem. (I am especially referring to some of your other questions, as this one even does make sense to some minro degree) – H.B. Sep 15 '11 at 07:39

1 Answers1

3

Try this..

oXL.quit()

// Note, oXL still points to excel

System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oXL)
oXL = Nothing
Sam Casil
  • 938
  • 1
  • 11
  • 16