cannot kill excel process

C

charmis

Hi everyone,

I am trying to include one feature using excel object in my application.

I am giving the code to create and kill the process , that i got from
Microsoft site.......but nothing is happening

it will create one process but , it wont close . i used the code from the
link below:

http://www.dotnet247.com/247reference/a.aspx?u=http://support.microsoft.com/?kbid=317109

How can i kill the process?

Also will this work in Windows server 2003





// function

private void NAR(object o)

{

try

{

System.Runtime.InteropServices.Marshal.ReleaseComObject(o);

}

catch {}

finally

{

o = null;

}

}





// button click

private void Button1_Click(object sender, System.EventArgs e)

{


PIA.ApplicationClass excelApplication = new PIA.ApplicationClass();

PIA.Workbook excelWorkbook =
((PIA.Workbook)excelApplication.Workbooks.Add(System.Reflection.Missing.Value));

PIA.Worksheet excelSheet = ((PIA.Worksheet)(excelWorkbook.ActiveSheet));

NAR(excelSheet);

excelWorkbook.Close(false,null,null);

NAR(excelWorkbook);

excelApplication.Quit();

NAR(excelApplication);


Debug.WriteLine("Sleeping...");

System.Threading.Thread.Sleep(1000);

Debug.WriteLine("End Excel");

GC.Collect();

GC.WaitForPendingFinalizers();


}

thanks & regards

charmis
 
T

Tom Kaminski [MVP]

charmis said:
Hi everyone,

I am trying to include one feature using excel object in my application.

I am giving the code to create and kill the process , that i got from
Microsoft site.......but nothing is happening

it will create one process but , it wont close . i used the code from the
link below:
http://www.dotnet247.com/247reference/a.aspx?u=http://support.microsoft.com/?kbid=317109

Don't use that example, it is for client-side code. It is a bad practice to
use Office objects in server-side code:
http://support.microsoft.com/kb/257757

Find an alternate way to do what you need.
 
E

Elton Wang

After releasing Com Object, force Garbage Collection, you
will kill EXCEL process immediately:

exBook.Close();
app.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject
(app);
GC.Collect();

Elton Wang
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top