Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Excel Process Still Running

I have an Windows Forms application that uses the Excel application to create
a spreadsheet, saves it and then quits the excel application - all
programmatically. The problem is that the Excel.exe process remains running
in the background until the windows forms application is exited. I've tried
the following:

//FIRST TRY:

/**Do Garbage Collection as suggested as best practice at:
* http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx
*/
excelWorkBooks = null;
mainbook = null;
sheet = null;
someRange = null;
/**Quit the application.*/
excelApplication.Quit();
excelApplication = null;
/**Collect Garbage (Twice).*/
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();

//SECOND TRY

private void releaseCOMObject(object COMObject){
try {
if(COMObject != null)

while(System.Runtime.InteropServices.Marshal.Relea seComObject(COMObject)0);
}
finally {
COMObject = null;
}
}

//THIRD TRY:
private void releaseCOMObject(object COMObject){
try {
if(COMObject != null)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(COMObject);
}
finally {
COMObject = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}

The methods are invoked after the application is done using the COM objects.

How can I close the Excel.exe process?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Excel Process Still Running

This is a common problem that I've not seen a clear solution for. Any
examples or web links would be helpful.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Excel Process Still Running

Most cases of Excel (or other server) failing to close are due to remaining
references.

You need to make sure that EVERY object referenced goes through your
excelApplication object.
Do not use any unqualified objects, as you will then be creating references
to Excel that you cannot set to nothing.

NickHK

"DeveloperSQL" wrote in message
...
I have an Windows Forms application that uses the Excel application to

create
a spreadsheet, saves it and then quits the excel application - all
programmatically. The problem is that the Excel.exe process remains

running
in the background until the windows forms application is exited. I've

tried
the following:

//FIRST TRY:

/**Do Garbage Collection as suggested as best practice at:
* http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx
*/
excelWorkBooks = null;
mainbook = null;
sheet = null;
someRange = null;
/**Quit the application.*/
excelApplication.Quit();
excelApplication = null;
/**Collect Garbage (Twice).*/
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();

//SECOND TRY

private void releaseCOMObject(object COMObject){
try {
if(COMObject != null)


while(System.Runtime.InteropServices.Marshal.Relea seComObject(COMObject)0);
}
finally {
COMObject = null;
}
}

//THIRD TRY:
private void releaseCOMObject(object COMObject){
try {
if(COMObject != null)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(COMObject);
}
finally {
COMObject = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}

The methods are invoked after the application is done using the COM

objects.

How can I close the Excel.exe process?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Excel Process Still Running

Is there a way to get a debug dump of the active COM objects related to
Excel? I've released all of the COM Objects in my application and Excel.exe
still continues to run.

"NickHK" wrote:

Most cases of Excel (or other server) failing to close are due to remaining
references.

You need to make sure that EVERY object referenced goes through your
excelApplication object.
Do not use any unqualified objects, as you will then be creating references
to Excel that you cannot set to nothing.

NickHK

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Excel Process Still Running

Is there a tool that can be used to debug/identify lingering references?

"DeveloperSQL" wrote:

Is there a way to get a debug dump of the active COM objects related to
Excel? I've released all of the COM Objects in my application and Excel.exe
still continues to run.

"NickHK" wrote:

Most cases of Excel (or other server) failing to close are due to remaining
references.

You need to make sure that EVERY object referenced goes through your
excelApplication object.
Do not use any unqualified objects, as you will then be creating references
to Excel that you cannot set to nothing.

NickHK

Reply
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
Excel window closed but process still running Jessica[_5_] Excel Programming 2 June 23rd 06 02:44 AM
Urgent Help needed - I need to stop a process that is running forever in Excel shadestreet Excel Discussion (Misc queries) 2 October 6th 05 09:59 PM
How to count process running time ( process not finished) miao jie Excel Programming 0 January 13th 05 09:23 AM
How to count process running time ( process not finished) miao jie Excel Programming 2 January 12th 05 06:01 AM
Excel process remains running Josh[_5_] Excel Programming 2 September 11th 03 04:22 PM


All times are GMT +1. The time now is 09:23 AM.

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

About Us

"It's about Microsoft Excel"