D
DeveloperSQL
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/library/aa679807(office.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.ReleaseComObject(COMObject)>0);
}
finally {
COMObject = null;
}
}
//THIRD TRY:
private void releaseCOMObject(object COMObject){
try {
if(COMObject != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(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?
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/library/aa679807(office.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.ReleaseComObject(COMObject)>0);
}
finally {
COMObject = null;
}
}
//THIRD TRY:
private void releaseCOMObject(object COMObject){
try {
if(COMObject != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(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?