Possible Duplicate:
Killing an interop Application process
I am using Microsoft.Office.Interop.Excel in order to get data from excel. Even though i clear the COM objects it still leaves some instances of EXEL.EXE in the background.Check my code below.
finally
{
if (cells != null) Marshal.FinalReleaseComObject(cells);
if (range != null) Marshal.FinalReleaseComObject(range);
if (sheets != null) Marshal.FinalReleaseComObject(sheets);
if (workSheet != null) Marshal.FinalReleaseComObject(workSheet);
if (excelWorkBook != null)
{
excelWorkBook.Close(Type.Missing, Type.Missing, Type.Missing);
Marshal.FinalReleaseComObject(excelWorkBook);
}
if (excelWorkbooks != null) Marshal.FinalReleaseComObject(excelWorkbooks);
if (excel != null)
{
excel.Quit();
Marshal.FinalReleaseComObject(excel);
}
cells = null;
range = null;
sheets = null;
workSheet = null;
excelWorkBook = null;
excelWorkbooks = null;
excel = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
Please tell me where I have gone wrong.