I'm using the Excel interop in C# ( ApplicationClass
) and have placed the following code in my finally clause: 我在C#( ApplicationClass
)中使用Excel互操做,并将如下代码放在个人finally子句中: app
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(excelSheet) != 0) { } excelSheet = null; GC.Collect(); GC.WaitForPendingFinalizers();
Although this kind of works, the Excel.exe
process is still in the background even after I close Excel. 尽管这种工做有效,可是即便我关闭Excel, Excel.exe
进程仍在后台。 It is only released once my application is manually closed. 仅在个人应用程序手动关闭后才释放它。 this
What am I doing wrong, or is there an alternative to ensure interop objects are properly disposed of? 我在作什么错,仍是有其余方法能够确保互操做对象获得正确处理? spa