2011年2月21日 星期一

Kill Excel.exe Process in C# .NET

使用 Interop.Excel 時就算相關資源都已釋放,但除非 winform 關閉否則還是會殘留一個process
這裡有一篇文章教你強制關閉process

以下為釋放資源範例
for (int i = 1; i <= sheets.Count; i++) Marshal.FinalReleaseComObject(sheets[i]);
Marshal.FinalReleaseComObject(sheets);
Marshal.FinalReleaseComObject(xlsbook);
xlsbooks.Close();
Marshal.FinalReleaseComObject(xlsbooks);
xlsapp.Quit();
Marshal.FinalReleaseComObject(xlsapp);
GC.Collect();

沒有留言:

自訂權限驗證機制

// 使用 filter [Route("api/[controller]")] [ApiController] [Authorize] [TypeFilter(typeof(CustomAsyncAuthorizationFilter))] public c...