LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Excel Instance not cleaned in Task Manager (Interop)

The following approach to code solved the problem

1) set the object to null when declraing all the object
Example:
Excel.Application xlApp = null;
Excel.Workbooks xlWorkBooks = null;
Excel.Workbook xlWorkBook = null;
Excel.Worksheet xlWorkSheet = null;

2) Instantiate object properly. Expecially create the Workbooks object and
then the Workbook object. Earlier i created the workbook directly bu using
Excel.WorkBooks.Add
Now it looks like
xlApp = new Excel.ApplicationClass();
xlWorkBooks = xlApp.Workbooks;
xlWorkBook = xlWorkBooks.Add(misValue);
xlWorkSheet = new Microsoft.Office.Interop.Excel.Worksheet();
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.Add

(misValue, misValue, misValue, misValue);

3) Release the com objects and set them to null.
NOTE: Each of the com objects created need to be released

Done by adding the Finally code

finally
{

// Destroy objects
if (xlApp != null)
{
xlWorkBook.Close(false, misValue, misValue);
xlWorkBooks.Close();
xlApp.Quit();
if (xlWorkSheet != null)
while
(System.Runtime.InteropServices.Marshal.ReleaseCom Object(xlWorkSheet) != 0) {
}
//if (xlWorkSheets != null)
// while
(System.Runtime.InteropServices.Marshal.ReleaseCom Object(xlWorkSheets) != 0)
{ }
if (xlWorkBook != null)
while
(System.Runtime.InteropServices.Marshal.ReleaseCom Object(xlWorkBook) != 0) { }
if (xlWorkBooks != null)
while
(System.Runtime.InteropServices.Marshal.ReleaseCom Object(xlWorkBooks) != 0) {
}
if (xlApp != null)
while
(System.Runtime.InteropServices.Marshal.ReleaseCom Object(xlApp) != 0) { }

xlWorkSheet = null;
//xlWorkSheets = null;
xlWorkBook = null;
xlWorkBooks = null;
xlApp = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}


The above considerations solved the problem
The excel instance mainly was not getting deleted as the count was not
getting decremented (not all objects were released) and was not 0
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Task Manager (shut down a task if active) Brettjg Excel Programming 2 February 21st 09 04:01 AM
excel.exe is not terminating from task manager Inthi Excel Programming 0 November 28th 05 01:39 PM
Instance still there in task manager after xlapp.Application.Quit Mo[_8_] Excel Programming 4 October 27th 05 04:36 PM
Task Manager and Excel 2003 Mike Excel Discussion (Misc queries) 1 April 20th 05 10:40 PM
EXCEL keeps running in task manager Sam Excel Programming 4 January 22nd 04 11:17 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"