Reading excel files in vb.net leaves excel process hanging

后端 未结 2 1700
梦毁少年i
梦毁少年i 2020-12-10 21:16

The following code works fine but seems to leave instances of excel.exe running in the background. How do I go about closing out this sub properly?

    Priv         


        
2条回答
  •  臣服心动
    2020-12-10 21:40

    I ran into this problem and what I found worked was making sure I called the Close() method on all Workbook and Workbooks objects, as well as the Quit() method on the Excel Application object. I also call System.Runtime.InteropServices.Marshal.ReleaseComObject on every Excel object was instantiated. I do all this in reverse order of age, so the newest object gets cleaned up first and the oldest, which is the Application object, gets taken care of last. I don't know if the order really matters, but it seems like it might.

    I've seen examples where GC.Collect() was called at the very end, but I've never had to do that to get the excel.exe process to end.

提交回复
热议问题