View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mo Mo is offline
external usenet poster
 
Posts: 69
Default 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