Excel Won't close in .NET 3.5 using C#

M

Mo

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.ReleaseComObject(xlApp);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(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.ReleaseComObject(xlRng);
xlRng = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
xlSheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
xlBook = null;
xlApp.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
xlApp = null;

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top