why unable kill Excel process?

wupeijun

New member
Joined
Apr 6, 2003
Messages
3
If use workbook object then unable kill the excel process

code as follows:
C#:
public void CreateExcel(DataView dv,string path,string title1)
{
	Excel.Application excel;
	try
	{
		excel =new Excel.Application();
	}
	catch
	{
		Response.Write("
 
Last edited by a moderator:
Does that mean Excel cant be closed if running within web application? I m experiencing the similar problem where Excel process is still running.

Many thanks.
 
My Dear at the end of your applicaton your must

1- Close the document which you opened or created through code
2- Kill the excel process by sending command Excel.Application.Close or something like this in aplication object methods

other wise your object would remain in memory. and in future development please remember one thing whenever you try to call any Ofifce asseomblies, remeber to mention its CLOSE methods
 
Nice try Madz. It would be nice if this issue was as simple as calling "Excel.Application.Close or something like this". You are trying to trivialize an issue that is much deeper than what it appears. When you use managed code to access an Office Application, a Runtime Callable Wrapper is created that keeps a reference count on the COM object (in this case, an office application). Therefore, all references must be released on the RCW or the COM object will not quit (even when calling the close or quit method of the object).

For detailed information on this subject research Interop Services for Microsoft Office. To release references on the RCW lookup "System.Runtime.InteropServices.Marshal.ReleaseComObject(o)". There are several good articles published on the web that address this issue.

Also, you may not see the Excel object terminate immediately in the task manager. The GC will terminate it in its own time (usually within 10 minutes).
 
Last edited by a moderator:
COM Interoperability and Windows Forms

Ive found that the Excel application object is bound to the main application thread when used in a windows form. This is not the case in a command prompt thread. Youll notice that the close & quit code *works* in a command prompt application, but in a windows form, it sticks around until the window closes.


//This code, flat out.. does not work. It doesnt quit the Excel object in a windows form.


writeExcel();

workbook.Close(true, Environment.CurrentDirectory + "exc" + DateTime.Now.Ticks.ToString() + ".xls", false);
exc.Quit();

Marshal.ReleaseComObject(exc); //This is supposed to trash the object. It Lies!

/* Ive tried with and without this.
GC.WaitForPendingFinalizers();
*/

GC.Collect(); // This *should* force the GC to clean up.. thus not requiring the 10 minute wait. Since this fires, exc must not be getting trashed.

So I stuffed writeExcel() into its own thread..
If I call txlThread.Abort() on the thread, it works.. but jesus isnt that kind of messy? :\

Also, this would necessitate me setting up an event for when writeExcel() is through.. Otherwise you can kill the thread before its done its job.

There Has to be a more graceful way to do this.

Also .. Did anyone notice that when you define the excel Application object, you get an Ambiguous reference? I have to use Excel.ApplicationClass Excel.WorkbookClass etc...

Im wondering if there is a scope issue here at work behind the scenes that isnt getting handled well.
 
Back
Top