cannot kill excel process

Discussion in 'ASP .Net' started by charmis, Jan 11, 2005.

  1. charmis

    charmis Guest

    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
     
    charmis, Jan 11, 2005
    #1
    1. Advertising

  2. "charmis" <> wrote in message
    news:...
    > 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.
     
    Tom Kaminski [MVP], Jan 11, 2005
    #2
    1. Advertising

  3. charmis

    Elton Wang Guest

    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


    >-----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.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
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >.
    >
     
    Elton Wang, Jan 11, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Tkachev

    How can I kill an "Excel" process from a memory?

    Michael Tkachev, Oct 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,286
    =?Utf-8?B?RXRoZW0gQXp1bg==?=
    Oct 18, 2004
  2. =?Utf-8?B?Q2hyaXNGcm9obGljaA==?=

    ASP.NET: Can't Kill EXCEL.exe with Office PIA

    =?Utf-8?B?Q2hyaXNGcm9obGljaA==?=, Apr 14, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    8,160
    =?Utf-8?B?S2VpdGg=?=
    Apr 25, 2006
  3. ary
    Replies:
    0
    Views:
    683
  4. ary
    Replies:
    2
    Views:
    850
  5. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,548
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
Loading...

Share This Page