如何正確清理Excel互操做對象? - How do I properly clean up Excel interop objects?

問題:

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


解決方案:

參考一: https://stackoom.com/question/fHm/如何正確清理Excel互操做對象
參考二: https://oldbug.net/q/fHm/How-do-I-properly-clean-up-Excel-interop-objects
相關文章
相關標籤/搜索