如何发布Excel流程? [英] How to release excel process?
本文介绍了如何发布Excel流程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Excel互操作,每次调用时似乎都在创建一个进程
I'm using the Excel interop and it seems to be creating a process every time I call
new Microsoft.Office.Interop.Excel.Application()
即使我打电话也永远不会结束该过程
And never ending the process even though I call
xlApp.Quit();
如何结束流程?
推荐答案
您要发布所有参考吗? (这意味着您必须首先保存它们.)
Are you releasing all of your references? (Which means you have to save them in the first place).
例如,这是我通过一些excel interop()处理的事情:
For example here's what's in my dispose from some excel interop():
public void Dispose()
{
if(!this.disposed)
{
if(cell != null)
Marshal.FinalReleaseComObject(cell);
if(cells != null)
Marshal.FinalReleaseComObject(cells);
if(worksheet != null)
Marshal.FinalReleaseComObject(worksheet);
if(worksheets != null)
Marshal.FinalReleaseComObject(worksheets);
if (workbook != null)
{
workbook.Close(false, Type.Missing, Type.Missing);
Marshal.FinalReleaseComObject(workbook);
}
Marshal.FinalReleaseComObject(workbooks);
xlApp.Quit();
Marshal.FinalReleaseComObject(xlApp);
GC.Collect();
GC.WaitForPendingFinalizers();
disposed = true;
}
}
(不确定这是否完美,但对我有用!)
(Not sure if this is perfect but it worked for me!)
这篇关于如何发布Excel流程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文