I have a simple web application which uses the Excel Interop libraries to read and insert into an Excel spreadsheet. I'm taking my due diligence to ensure that I don't use two dots and to ensure that all COM object references are released by using Marshal.ReleaseComObject()
and GC.Collect()
, but there开发者_StackOverflow is still an EXCEL.EXE process running on my server.
I've created a Windows Forms application that uses the same object releasing process as in my ASP.NET app, and it ends the process successfully. Is there something involved with using the Interop libraries with ASP.NET that I've overlooked?
EDIT: As a shot in the dark, maybe permissions need to be set up in a specific way on the server? I'm using <identity impersonate="true"/>
in my web.config file and am a local administrator on the server.
I'm not sure this is exactly an answer but I have worked a lot with ASP.NET and Excel Interop and can offer you some of my observations / pointers.
If you use Task Manager you can see which user is still running EXCEL.EXE process - it's most likely the AppPool Identity.
From experience when the app pool recycles this will close Excel.
Also you may notice that if you run your script again a second Excel opens and will close!
For reference, here is my Close Excel code:
xl.Quit();
Marshal.ReleaseComObject(xl);
xl = null;
GC.Collect();
精彩评论