Differences between the method of closing a excel file

I have been using some functions for a while, and now I'm actually wondering, what is the difference between them. I know, that xlWorkbook.Close(0) closes the file, xlAppQuit(); quits the excel application, and Marshal.ReleaseComObject(xlWorkbook); cleans up - releases COM objects. But what does it mean in practice? I just can't imagine the differences. The first two make my excel process dissapear from the Task Manager (so how is closing a workbook different than quitting if they both kill the excel process?), the last one does not.


You need to remember those classes you call are COM objects. COM uses reference counting. So each time you use one of them in the backgound it +1's.

To properly clean up you need to decrement that counter. That is done through releasing your reference (wb=null) and then calling Marshall.ReleaseComObject(...).

If you fail do do so you introduce a memory leak as those COM objects stick around until your application is closed.

链接地址: http://www.djcxy.com/p/35670.html

上一篇: 使用Excel Interop打开Excel工作簿时出现问题

下一篇: 关闭excel文件的方法之间的差异