可能重复:
终止互操作应用程序进程
我正在使用 Microsoft.Office.Interop.Excel 以从 excel 中获取数据。即使我清除了 COM 对象,它仍然会在后台留下一些 EXEL.EXE 实例。检查下面的代码。
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();
}
请告诉我哪里出错了。