Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > cannot kill excel process

Reply
Thread Tools

cannot kill excel process

 
 
charmis
Guest
Posts: n/a
 
      01-11-2005
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/247referenc...m/?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.ReleaseComO bject(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(Syst em.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












 
Reply With Quote
 
 
 
 
Tom Kaminski [MVP]
Guest
Posts: n/a
 
      01-11-2005
"charmis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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/247referenc...m/?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.


 
Reply With Quote
 
 
 
 
Elton Wang
Guest
Posts: n/a
 
      01-11-2005
After releasing Com Object, force Garbage Collection, you
will kill EXCEL process immediately:

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

Elton Wang
http://www.velocityreviews.com/forums/(E-Mail Removed)

>-----Original Message-----
>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.ReleaseCom Object

(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
>
>
>
>
>
>
>
>
>
>
>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot delete a file the process cannot access the file because it is being used by another process ASp.net 2 ary ASP .Net 2 11-29-2006 04:30 AM
Cannot delete a file the process cannot access the file because it is being used by another process ASp.net 2 ary ASP .Net 0 11-28-2006 09:13 AM
Cannot Copy Assembly <MyAssembly> The Process Cannot Access The File Because It Is Being Used By Another Process Ram ASP .Net 2 06-30-2005 11:30 AM
Bava's KILL BABY KILL widescreen drsd2kill DVD Video 0 11-27-2004 12:04 AM
How can I kill an "Excel" process from a memory? Michael Tkachev ASP .Net 1 10-18-2004 12:13 PM



Advertisments