Kill Process

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

    Kill Process


    I use late binding to have my program compatible with multiple versions of Microsoft Outlook.
    Here is a snipped of my code that launches Microsoft Outlook and displays it to the user:

    Code:
    Type objClassType = Type.GetTypeFromProgID("Outlook.Application", true);
    object objApp_Late = Activator.CreateInstance(objClassType);
    
    // .... code here that does something .... //
    
    object[] parameters = new object[1];
    parameters[0] = objApp_Late;
    objMailItem_Late.GetType().InvokeMember("Display", BindingFlags.InvokeMethod, null, objMailItem_Late, parameters);
    At the very end I display the instance to the user so s/he can interact with Outlook, while my program continues on. I noticed that
    when the user closes Outlook and continues using my program, OUTLOOK.EXE still lives on when you look in the task manager list,
    wasting memory space. When my app opens up Outlook again and the user closes it another OUTLOOK.EXE instance remains in memory and
    so on.

    How can I stop this from happening? Is it possible to wait for user to quit Outlook and return to my program and clean up, or is
    there a way to just kill OUTLOOK.EXE once it's closed by the user. Any idea why OUTLOOK.EXE hangs on even after it is closed by the
    user?

    Cheers,
    Max


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Kill Process

    Max,

    Outlook hangs around because you still have references that are attached
    to it. Even if you think that you have properly freed all of the
    references, objects in outlook (or any office product for that matter) have
    circular references, which makes them notoriously hard to release in this
    environment.

    The easiest way to get rid of everything is to make sure that all
    references to all outlook objects are set to null and then perform a garbage
    collection. This will release all of the references that you have, and
    should still keep the app running, such that when you close it (equivalent
    to calling Quit on the application object) it will terminate correctly.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Max" <maxy_100@yahoo .com> wrote in message
    news:ejAaQWSyFH A.3312@TK2MSFTN GP09.phx.gbl...[color=blue]
    >
    > I use late binding to have my program compatible with multiple versions of
    > Microsoft Outlook.
    > Here is a snipped of my code that launches Microsoft Outlook and displays
    > it to the user:
    >
    >
    Code:
    >
    > Type objClassType = Type.GetTypeFromProgID("Outlook.Application", true);
    > object objApp_Late = Activator.CreateInstance(objClassType);
    >
    > // .... code here that does something .... //
    >
    > object[] parameters = new object[1];
    > parameters[0] = objApp_Late;
    > objMailItem_Late.GetType().InvokeMember("Display",
    > BindingFlags.InvokeMethod, null, objMailItem_Late, parameters);
    >
    >
    >
    > At the very end I display the instance to the user so s/he can interact
    > with Outlook, while my program continues on. I noticed that when the user
    > closes Outlook and continues using my program, OUTLOOK.EXE still lives on
    > when you look in the task manager list, wasting memory space. When my app
    > opens up Outlook again and the user closes it another OUTLOOK.EXE instance
    > remains in memory and so on.
    >
    > How can I stop this from happening? Is it possible to wait for user to
    > quit Outlook and return to my program and clean up, or is there a way to
    > just kill OUTLOOK.EXE once it's closed by the user. Any idea why
    > OUTLOOK.EXE hangs on even after it is closed by the user?
    >
    > Cheers,
    > Max
    >
    >[/color]


    Comment

    • Mel Weaver

      #3
      Re: Kill Process

      Try this


      Mel

      "Max" <maxy_100@yahoo .com> wrote in message
      news:ejAaQWSyFH A.3312@TK2MSFTN GP09.phx.gbl...[color=blue]
      >
      > I use late binding to have my program compatible with multiple versions of
      > Microsoft Outlook.
      > Here is a snipped of my code that launches Microsoft Outlook and displays
      > it to the user:
      >
      >
      Code:
      >
      > Type objClassType = Type.GetTypeFromProgID("Outlook.Application", true);
      > object objApp_Late = Activator.CreateInstance(objClassType);
      >
      > // .... code here that does something .... //
      >
      > object[] parameters = new object[1];
      > parameters[0] = objApp_Late;
      > objMailItem_Late.GetType().InvokeMember("Display",
      > BindingFlags.InvokeMethod, null, objMailItem_Late, parameters);
      >
      >
      >
      > At the very end I display the instance to the user so s/he can interact
      > with Outlook, while my program continues on. I noticed that when the user
      > closes Outlook and continues using my program, OUTLOOK.EXE still lives on
      > when you look in the task manager list, wasting memory space. When my app
      > opens up Outlook again and the user closes it another OUTLOOK.EXE instance
      > remains in memory and so on.
      >
      > How can I stop this from happening? Is it possible to wait for user to
      > quit Outlook and return to my program and clean up, or is there a way to
      > just kill OUTLOOK.EXE once it's closed by the user. Any idea why
      > OUTLOOK.EXE hangs on even after it is closed by the user?
      >
      > Cheers,
      > Max
      >
      >[/color]


      Comment

      • Max

        #4
        Re: Kill Process


        Thanks for the link. It seems to be working for Excel like the example but not for Outlook.
        I wonder why Outlook has to be such a memory parasite....



        "Mel Weaver" <Mel@[remove spam]insdirect.com> wrote in message news:unx67sSyFH A.2348@TK2MSFTN GP15.phx.gbl...[color=blue]
        > Try this
        > http://support.microsoft.com/default...;EN-US;Q317109
        >
        > Mel
        >
        > "Max" <maxy_100@yahoo .com> wrote in message
        > news:ejAaQWSyFH A.3312@TK2MSFTN GP09.phx.gbl...[color=green]
        >>
        >> I use late binding to have my program compatible with multiple versions of
        >> Microsoft Outlook.
        >> Here is a snipped of my code that launches Microsoft Outlook and displays
        >> it to the user:
        >>
        >>
        Code:
        >>
        >> Type objClassType = Type.GetTypeFromProgID("Outlook.Application", true);
        >> object objApp_Late = Activator.CreateInstance(objClassType);
        >>
        >> // .... code here that does something .... //
        >>
        >> object[] parameters = new object[1];
        >> parameters[0] = objApp_Late;
        >> objMailItem_Late.GetType().InvokeMember("Display",
        >> BindingFlags.InvokeMethod, null, objMailItem_Late, parameters);
        >>
        >>
        >>
        >> At the very end I display the instance to the user so s/he can interact
        >> with Outlook, while my program continues on. I noticed that when the user
        >> closes Outlook and continues using my program, OUTLOOK.EXE still lives on
        >> when you look in the task manager list, wasting memory space. When my app
        >> opens up Outlook again and the user closes it another OUTLOOK.EXE instance
        >> remains in memory and so on.
        >>
        >> How can I stop this from happening? Is it possible to wait for user to
        >> quit Outlook and return to my program and clean up, or is there a way to
        >> just kill OUTLOOK.EXE once it's closed by the user. Any idea why
        >> OUTLOOK.EXE hangs on even after it is closed by the user?
        >>
        >> Cheers,
        >> Max
        >>
        >>[/color]
        >
        >[/color]

        Comment

        Working...