Close an app in C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richie

    Close an app in C#

    Hi all,

    I want to close excel application from C#, this is the piece of code I am
    trying

    "System.Runtime .InteropService s.Marshal.Relea seComObject(exc elApp);"

    GC.Collect();

    It ain't working ! Any ideas please !!

    Thanks.






  • Jakob Christensen

    #2
    RE: Close an app in C#

    Assuming that your variable excelApp is just a reference to an Excel
    Application, all you have to do is call excelApp.Quit() ;

    HTH, Jakob.


    "Richie" wrote:
    [color=blue]
    > Hi all,
    >
    > I want to close excel application from C#, this is the piece of code I am
    > trying
    >
    > "System.Runtime .InteropService s.Marshal.Relea seComObject(exc elApp);"
    >
    > GC.Collect();
    >
    > It ain't working ! Any ideas please !!
    >
    > Thanks.
    >
    >
    >
    >
    >
    >
    >[/color]

    Comment

    • Richie

      #3
      Re: Close an app in C#

      Hi Richie,

      This is fine, but on viewing "Task List" the application tab shows
      "Excel.exe" running. And if I run the program again the message
      "Administra tor is using the file, file will open in readonly mode" shows.

      Any ideas ?



      "Jakob Christensen" <jch@REMOVEpens ion.dk> wrote in message
      news:AF7A8DC6-DDDF-4735-88EB-B835F521B0CD@mi crosoft.com...[color=blue]
      > Assuming that your variable excelApp is just a reference to an Excel
      > Application, all you have to do is call excelApp.Quit() ;
      >
      > HTH, Jakob.
      >
      >
      > "Richie" wrote:
      >[color=green]
      > > Hi all,
      > >
      > > I want to close excel application from C#, this is the piece of code I[/color][/color]
      am[color=blue][color=green]
      > > trying
      > >
      > > "System.Runtime .InteropService s.Marshal.Relea seComObject(exc elApp);"
      > >
      > > GC.Collect();
      > >
      > > It ain't working ! Any ideas please !!
      > >
      > > Thanks.
      > >
      > >
      > >
      > >
      > >
      > >
      > >[/color][/color]


      Comment

      • Jakob Christensen

        #4
        Re: Close an app in C#

        It sounds like you may be holding a reference to some of the Excel COM
        objects. Did you try calling ReleaseComObjec t until it returns 0 on all your
        references before calling Quit()?

        "Richie" wrote:
        [color=blue]
        > Hi Richie,
        >
        > This is fine, but on viewing "Task List" the application tab shows
        > "Excel.exe" running. And if I run the program again the message
        > "Administra tor is using the file, file will open in readonly mode" shows.
        >
        > Any ideas ?
        >
        >
        >
        > "Jakob Christensen" <jch@REMOVEpens ion.dk> wrote in message
        > news:AF7A8DC6-DDDF-4735-88EB-B835F521B0CD@mi crosoft.com...[color=green]
        > > Assuming that your variable excelApp is just a reference to an Excel
        > > Application, all you have to do is call excelApp.Quit() ;
        > >
        > > HTH, Jakob.
        > >
        > >
        > > "Richie" wrote:
        > >[color=darkred]
        > > > Hi all,
        > > >
        > > > I want to close excel application from C#, this is the piece of code I[/color][/color]
        > am[color=green][color=darkred]
        > > > trying
        > > >
        > > > "System.Runtime .InteropService s.Marshal.Relea seComObject(exc elApp);"
        > > >
        > > > GC.Collect();
        > > >
        > > > It ain't working ! Any ideas please !!
        > > >
        > > > Thanks.
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >[/color][/color]
        >
        >
        >[/color]

        Comment

        • Jakob Christensen

          #5
          Re: Close an app in C#

          It sounds like you may be holding a reference to some of the Excel COM
          objects. Did you try calling ReleaseComObjec t until it returns 0 on all your
          references before calling Quit()?

          "Richie" wrote:
          [color=blue]
          > Hi Richie,
          >
          > This is fine, but on viewing "Task List" the application tab shows
          > "Excel.exe" running. And if I run the program again the message
          > "Administra tor is using the file, file will open in readonly mode" shows.
          >
          > Any ideas ?
          >
          >
          >
          > "Jakob Christensen" <jch@REMOVEpens ion.dk> wrote in message
          > news:AF7A8DC6-DDDF-4735-88EB-B835F521B0CD@mi crosoft.com...[color=green]
          > > Assuming that your variable excelApp is just a reference to an Excel
          > > Application, all you have to do is call excelApp.Quit() ;
          > >
          > > HTH, Jakob.
          > >
          > >
          > > "Richie" wrote:
          > >[color=darkred]
          > > > Hi all,
          > > >
          > > > I want to close excel application from C#, this is the piece of code I[/color][/color]
          > am[color=green][color=darkred]
          > > > trying
          > > >
          > > > "System.Runtime .InteropService s.Marshal.Relea seComObject(exc elApp);"
          > > >
          > > > GC.Collect();
          > > >
          > > > It ain't working ! Any ideas please !!
          > > >
          > > > Thanks.
          > > >
          > > >
          > > >
          > > >
          > > >
          > > >
          > > >[/color][/color]
          >
          >
          >[/color]

          Comment

          Working...