[英]Clean Com components when host the asp.net website in IIS
我在IIS中托管了一个网站。 我的应用程序全部关于将数据写入Excel文档和从Excel文档读取数据。
当我从VS运行应用程序时,我一直只能看到一个EXCEL.exe,但是当我在IIS中托管相同的应用程序时,每次编写其创建一个excel对象并在Task-manager中显示,因此有时我的网站会停止回应。
下面是我的代码
try
{
xlApp = new app.Application();
xlWorkBooks = xlApp.Workbooks;
xlWorkBook = xlWorkBooks.Open(FilePath, missing, false, missing, missing, missing, true, missing, missing, true, missing, missing, missing, missing, missing);
xlWorkSheet = xlWorkBook.Worksheets.get_Item(index);
//code …………………………….
xlApp.DisplayAlerts = false;
xlWorkBook.Save();
boolWriteSuccess = true;
xlApp.DisplayAlerts = true;
}
Catch()
{
}
finally
{
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.FinalReleaseComObject(xlWorkSheet);
Marshal.FinalReleaseComObject(xlWorkSheets);
xlWorkBook.Close(Type.Missing, Type.Missing, Type.Missing);
Marshal.FinalReleaseComObject(xlWorkBook);
xlWorkBooks.Close();
Marshal.FinalReleaseComObject(xlWorkBooks);
if (xlApp != null)
xlApp.Quit();
Marshal.FinalReleaseComObject(xlApp);
}
这是在IIS中托管网站时任务管理器的屏幕快照
我想始终从任务管理器中清除excel.exe,但是有些无法清除。 请在这方面帮助我。
保存excel后,您应该关闭工作簿。 每次创建nea app.application时,在保存以下代码的excel使用后,它将创建新的excel.exe
try {
foreach (Process proc in Process.GetProcessesByName("Excel"))
{
proc.Kill();
}}catch(Exception ex){
MessageBox.Show(ex.Message);}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.