Why does excel remain open? [duplicate]

我们两清 提交于 2019-12-01 11:37:45

I remember having seen that, after ReleaseComObject(), a forced GC pass is due for the object to be released and excel to finally die.

Also, I don't see it in that snippet, but you have to ReleaseComObject() in any sheet or other Excel object you might have gotten a handle on (is result such a thing?).

ReleaseComObject(result);
app.Aplication.Quit();
ReleaseComObject(app);
GC.Collect();

Is your function creating an error? If so the Quit() is never reached. You may want to put the Quit and ReleaseComObject in a finally block.

Try using

xlApp.Application.Quit();

instead of

xlApp.Quit();

I ran into exactly the same issue recently :)

Excel is a COM Automation Server.

Even though you call Application.Quit() and you Release the Reference to the COM object, the exe itself will not end. You will still be able to see it in task manager. Making further calls to Excel will use the running instance.

The Excel instance will exit after your application (thread, session, etc..) closes.

Ever get "RPC server not found/running" type COM errors? Now you know why.

See also (this has been asked many times on SO):

c# and excel automation - ending the running instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!