Excel ApplicationClassClass object still running after Quit Method
Tech-Today

Excel ApplicationClassClass object still running after Quit Method


Problem:
I have developed an application in Visual Studio C# that will read and write contents on an excel document. After I'm done coding, I've found several instances of the EXCEL application in the System's Task Manager.

I've googled and found this: http://support.microsoft.com/kb/Q317109

Unfortunately, it might be confusing for others, so here's what worked for me.

Don't do this:

workBook = excelApp.Workbooks.Open(docname, m, m, m, m, m, m, m, m, m, m, m, m, m, m);

Try to break the declaration like this:


//member variables
private Microsoft.Office.Interop.Excel.ApplicationClass excelApp;
private Workbooks workBooks;
private Workbook workBook;
private Worksheet workSheet;

//declared inside a method
excelApp = new ApplicationClass();
Missing m = Missing.Value;
workBooks = excelApp.Workbooks;
workBook = workBooks.Open(docname, m, m, m, m, m, m, m, m, m, m, m, m, m, m);


Then after you have finished editing your document, you have to close, dispose the object and reclaim the memory it used.


excelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(workBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workBooks);
GC.Collect();
GC.WaitForPendingFinalizers();


Note that we run ReleaseComObject on both workbook and workbooks object. Explanation is on the link from microsoft above.




- The Program Can't Start Because Api-ms-win-crt-runtime-l1-1-0.dll Is Missing
This problem is often encountered when running Microsoft Office, Adobe Products or even Apache server. Base on this entry from stack overflow: http://stackoverflow.com/questions/33265663/api-ms-win-crt-runtime-l1-1-0-dll-is-missing-when-opening-microsoft-office-file...

- Visual Studio 2008 Freeze After Installation Of Office 2010
I am curious with the new Office 2010 so I installed it to try it out. It was a successful installation no error or whatever. After a day I opened my Visual Studio 2008 and try coding, then it suddenly freezes. Looking at the tasklist, I found an unusual...

- Copy A File From Desktop/pc To A Pda Or Mobile Device And Vice Versa Using Rapi Api
Objective: -To copy a file from desktop to a pda device and vice versa using RAPI API. -http://msdn.microsoft.com/en-us/library/aa921197.aspx Requirement: -microsoft activesync must be installed -of course either .net framework 2 or greater To implement...

- Google Map Api - An Example Implementation In C#. Converts An Array Of String Addresses Into Longtitude, Latitude Pair
Objective: -To create a web application that will use the google map api to produce longtitude, latitude locations. The application will read string address values from an excel document. So it's also an excel reader. What you need: 1.) Visual Studio...

- How To Create A Java Application That Can Read And Write To An Excel's (microsoft Office) And Calc's (open Office) Worksheet
Requirements: -JOpenDocument: http://www.jopendocument.org/downloads.html (calc worksheet api) -Excel POI: http://poi.apache.org/download.html (excel worksheet api) -JUnit: http://sourceforge.net/project/showfiles.php?group_id=15278&package_id=12472...



Tech-Today








.