来自ASP.NET的Excel互操作 - 无法杀死进程 [英] Excel interop from ASP.NET - Process can't be killed
问题描述
嗨!
这个问题已经讨论了很多,但我还没有找到一个解决方案,
适用于ASP.NET。我有一个库,可以对Excel
文件进行一些操作,它将在ASP.NET应用程序中使用。如果我在Forms应用程序中使用
库,那么在完成
清理操作时将删除Excel进程,但是使用ASP.NET可以清除所有可能的方法
失败。
已尝试以下代码:
应用程序app = new ApplicationClass();
工作簿wb = null;
//一些代码...没有完成工作表参考,只做了wb.load,x =
wb.Worksheets.Count,wb.close
//发布工作簿
ReleaseComObject(wb);
wb = null ;
app.Quit();
ReleaseComObject(app);
app = null;
当从Windows应用程序调用该方法时,Excel现在已经消失,但是当从ASP.NET调用
时,Excel进程仍然存在。
所以我们收集过程必须手动杀死。关闭Win32
api找一些功能。瞧,我们找到了GetWindowThreadProcessId。但是
你知道什么?当从windows应用程序调用该方法时,过程
ID被填充并且我们可以终止进程,但是当从ASP.NET调用时,
进程ID是0,线程ID为0,Excel仍然挥之不去..
我已经准备好致力于当地的庇护......
>
任何帮助非常感谢......
Lars-Erik
尝试使用System.GC.Collect来强制清理所有COM对象后,使用它们完成了
。
HTH
问候
Joyjit
" Lars-Erik Aabech" < LA ************** @ markedspartner.noSPAMBLOCK>写在
消息新闻:OQ ************** @ tk2msftngp13.phx.gbl ...嗨!
这个问题已经讨论了很多,但是我还没有找到适用于ASP.NET的解决方案。我有一个库,可以对Excel
文档进行一些操作,它将在ASP.NET应用程序中使用。如果我在Forms应用程序中使用
库,那么在完成
清理操作时将删除Excel进程,但是使用ASP.NET所有可能的方法来清理
up失败。
以下代码已经尝试过:
应用程序app = new ApplicationClass();
工作簿wb = null;
//一些代码。 ..没有完成工作表参考,只做了wb.load,x =
wb.Worksheets.Count,wb.close
//发布工作簿
ReleaseComObject(wb);
wb = null;
app.Quit();
ReleaseComObject(app);
app = null;
当方法是从Windows应用程序调用,Excel现在已经消失,但是当从ASP.NET调用时,Excel进程仍然存在。
因此我们收集了该进程必须手动杀死的过程。关闭
Win32 api以找到一些功能。瞧,我们找到了GetWindowThreadProcessId。
但你知道什么?当从windows应用程序调用该方法时,
进程ID被填充并且我们可以终止该进程,但是当从ASP.NET调用时,
进程ID为0,线程ID为0,和Excel仍然挥之不去..
我准备好致力于当地的庇护......
任何帮助都非常感激......
Lars-Erik
我做到了。忘了将它包含在示例代码中。
还尝试了GC.WaitForPendingFinalizers()。
仍然没有雪茄......
>
LE
" Joyjit Mukherjee" <乔************** @ hotmail.com>在消息中写道
新闻:e6 ************** @ TK2MSFTNGP12.phx.gbl ...>
尝试使用System.GC.Collect在你完成使用后强行清理所有COM对象。
HTH
问候
Joyjit >
Lars-Erik Aabech < LA ************** @ markedspartner.noSPAMBLOCK>在消息新闻中写道:OQ ************** @ tk2msftngp13.phx.gbl ...嗨!
>这个问题已经讨论了很多,但我还没有找到适用于ASP.NET的解决方案
。我有一个库,可以对Excel
文档进行一些操作,它将在ASP.NET应用程序中使用。如果我在Forms应用程序中使用
库,则在完成
清理操作时会删除Excel进程,但是使用ASP.NET可以清除所有可能的方法
up < blockquote class =post_quotes>失败。
以下代码已尝试过:
Application app = new ApplicationClass();
Workbook wb = null;
//一些代码......没有完成工作表参考,只做了wb.load,x =
wb.Worksheets.Count,wb.close
//发布工作簿
ReleaseComObject(wb);
wb = null;
app.Quit();
ReleaseComObject(app);
app = null;
当从Windows应用程序调用该方法时,Excel现在已经消失了,但是当从ASP.NET调用时,
仍然是Excel进程。
所以我们聚集了该过程必须手动杀死。关闭
Win32api查找一些函数。 Et瞧,我们找到了GetWindowThreadProcessId。
但是你知道什么?当从Windows应用程序调用该方法时,
进程ID已填充,我们可以终止进程,但是从ASP.NET调用时,
进程ID是0,线程ID是0,而Excel仍然挥之不去
...
我已经准备好将其提交到当地的庇护...
任何帮助都非常感谢......
Lars-Erik
microsoft不推荐这种方法:
http://support.microsoft.com/default...b;EN-US;257757
这里是退出的解决方法
http://support.microsoft.com/default...b;EN-US;317109
- 布鲁斯(s qlwork.com)
" Lars-Erik Aabech" < LA ************** @ markedspartner.noSPAMBLOCK>写在
消息新闻:OQ ************** @ tk2msftngp13.phx.gbl ...嗨!
这个问题已经讨论了很多,但是我还没有找到适用于ASP.NET的解决方案。我有一个库,可以对Excel
文档进行一些操作,它将在ASP.NET应用程序中使用。如果我在Forms应用程序中使用
库,那么在完成
清理操作时将删除Excel进程,但是使用ASP.NET所有可能的方法来清理
up失败。
以下代码已经尝试过:
应用程序app = new ApplicationClass();
工作簿wb = null;
//一些代码。 ..没有完成工作表参考,只做了wb.load,x =
wb.Worksheets.Count,wb.close
//发布工作簿
ReleaseComObject(wb);
wb = null;
app.Quit();
ReleaseComObject(app);
app = null;
当方法是从Windows应用程序调用,Excel现在已经消失,但是当从ASP.NET调用时,Excel进程仍然存在。
因此我们收集了该进程必须手动杀死的过程。关闭
Win32 api以找到一些功能。瞧,我们找到了GetWindowThreadProcessId。
但你知道什么?当从windows应用程序调用该方法时,
进程ID被填充并且我们可以终止该进程,但是当从ASP.NET调用时,
进程ID为0,线程ID为0,和Excel仍然挥之不去..
我准备好致力于当地的庇护......
任何帮助都非常感激......
Lars-Erik
Hi!
This issue have been discussed a lot, but I haven''t found a solution that
applies to ASP.NET. I have a library which does some operations on Excel
documents, and it will be used in an ASP.NET application. If I use the
library in a Forms application, the Excel process is removed when the
cleanup operations are done, but with ASP.NET all possible ways to clean up
fails.
The following code has been tried:
Application app = new ApplicationClass();
Workbook wb = null;
// some code... no sheet reference done, only doing wb.load, x =
wb.Worksheets.Count, wb.close
// release workbook
ReleaseComObject(wb);
wb = null;
app.Quit();
ReleaseComObject(app);
app = null;
When the method is called from a windows app, Excel is now gone, but when
called from ASP.NET the Excel process remains.
So we gathered that the process had to be killed manually. Off to the Win32
api to find some functions. Et voila, we find GetWindowThreadProcessId. But
what do you know? When the method is called from a windows app, the process
ID is filled and we can kill the process, but when called from ASP.NET, the
process ID is 0, the thread ID is 0, and Excel is still lingering about..
I for one am ready to be committed to the local asylum...
Any help greatly appreciated......
Lars-Erik
Hi,
try System.GC.Collect to cleanup all COM objects forcefully after you
finished off using them.
HTH
Regards
Joyjit
"Lars-Erik Aabech" <la**************@markedspartner.noSPAMBLOCK> wrote in
message news:OQ**************@tk2msftngp13.phx.gbl...Hi!
This issue have been discussed a lot, but I haven''t found a solution that
applies to ASP.NET. I have a library which does some operations on Excel
documents, and it will be used in an ASP.NET application. If I use the
library in a Forms application, the Excel process is removed when the
cleanup operations are done, but with ASP.NET all possible ways to clean up fails.
The following code has been tried:
Application app = new ApplicationClass();
Workbook wb = null;
// some code... no sheet reference done, only doing wb.load, x =
wb.Worksheets.Count, wb.close
// release workbook
ReleaseComObject(wb);
wb = null;
app.Quit();
ReleaseComObject(app);
app = null;
When the method is called from a windows app, Excel is now gone, but when
called from ASP.NET the Excel process remains.
So we gathered that the process had to be killed manually. Off to the Win32 api to find some functions. Et voila, we find GetWindowThreadProcessId. But what do you know? When the method is called from a windows app, the process ID is filled and we can kill the process, but when called from ASP.NET, the process ID is 0, the thread ID is 0, and Excel is still lingering about..
I for one am ready to be committed to the local asylum...
Any help greatly appreciated......
Lars-Erik
I did. Forgot to include it in the sample code.
Also tried GC.WaitForPendingFinalizers().
Still no cigar...
L-E
"Joyjit Mukherjee" <jo**************@hotmail.com> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...Hi,
try System.GC.Collect to cleanup all COM objects forcefully after you
finished off using them.
HTH
Regards
Joyjit
"Lars-Erik Aabech" <la**************@markedspartner.noSPAMBLOCK> wrote in
message news:OQ**************@tk2msftngp13.phx.gbl...Hi!
This issue have been discussed a lot, but I haven''t found a solution that applies to ASP.NET. I have a library which does some operations on Excel
documents, and it will be used in an ASP.NET application. If I use the
library in a Forms application, the Excel process is removed when the
cleanup operations are done, but with ASP.NET all possible ways to clean
upfails.
The following code has been tried:
Application app = new ApplicationClass();
Workbook wb = null;
// some code... no sheet reference done, only doing wb.load, x =
wb.Worksheets.Count, wb.close
// release workbook
ReleaseComObject(wb);
wb = null;
app.Quit();
ReleaseComObject(app);
app = null;
When the method is called from a windows app, Excel is now gone, but when called from ASP.NET the Excel process remains.
So we gathered that the process had to be killed manually. Off to the
Win32api to find some functions. Et voila, we find GetWindowThreadProcessId.
Butwhat do you know? When the method is called from a windows app, the
processID is filled and we can kill the process, but when called from ASP.NET,
theprocess ID is 0, the thread ID is 0, and Excel is still lingering about..
I for one am ready to be committed to the local asylum...
Any help greatly appreciated......
Lars-Erik
microsoft does not recommend this approach:
http://support.microsoft.com/default...b;EN-US;257757
here is the workaround to do the exit
http://support.microsoft.com/default...b;EN-US;317109
-- bruce (sqlwork.com)
"Lars-Erik Aabech" <la**************@markedspartner.noSPAMBLOCK> wrote in
message news:OQ**************@tk2msftngp13.phx.gbl...Hi!
This issue have been discussed a lot, but I haven''t found a solution that
applies to ASP.NET. I have a library which does some operations on Excel
documents, and it will be used in an ASP.NET application. If I use the
library in a Forms application, the Excel process is removed when the
cleanup operations are done, but with ASP.NET all possible ways to clean up fails.
The following code has been tried:
Application app = new ApplicationClass();
Workbook wb = null;
// some code... no sheet reference done, only doing wb.load, x =
wb.Worksheets.Count, wb.close
// release workbook
ReleaseComObject(wb);
wb = null;
app.Quit();
ReleaseComObject(app);
app = null;
When the method is called from a windows app, Excel is now gone, but when
called from ASP.NET the Excel process remains.
So we gathered that the process had to be killed manually. Off to the Win32 api to find some functions. Et voila, we find GetWindowThreadProcessId. But what do you know? When the method is called from a windows app, the process ID is filled and we can kill the process, but when called from ASP.NET, the process ID is 0, the thread ID is 0, and Excel is still lingering about..
I for one am ready to be committed to the local asylum...
Any help greatly appreciated......
Lars-Erik
这篇关于来自ASP.NET的Excel互操作 - 无法杀死进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!