ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel Won't close in .NET 3.5 using C# (https://www.excelbanter.com/excel-programming/439560-excel-wont-close-net-3-5-using-c.html)

Mo

Excel Won't close in .NET 3.5 using C#
 
I have tryed all the various versions of closing an excel object, but it
still remains in the Task Manager.
CODE SAMPLE ONE: =====================================
xlBook.SaveAs(getFile, Excel.XlFileFormat.xlWorkbookNormal, null, null,
true, false, Excel.XlSaveAsAccessMode.xlShared, false, false, null, null,
null);

xlBook.Close(null, null, null);
xlApp.Workbooks.Close();
xlApp.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlApp);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlSheet);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlBook);

xlSheet = null;
xlBook = null;
xlApp = null;
GC.Collect(); // force final cleanup!

CODE SAMPLE TWO: =====================================
xlBook.Close(true, GLName, null);
xlApp.Workbooks.Close();

GC.Collect(); // force final cleanup!
GC.WaitForPendingFinalizers();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlRng);
xlRng = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlSheet);
xlSheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlBook);
xlBook = null;
xlApp.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlApp);
xlApp = null;

==================================================

I really hoped that this was fixed by now, I 've been fighting with this
since VB6... Any suggestion?
--
MJB


All times are GMT +1. The time now is 06:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com