Determining which Process has exited

Hi all,

I have had a quick search through the posts, but can't seem to find an answer to my question, which is....

I have a Service that manages 'n' instances of processes on a machine. The Service needs to be able to determine when a process exits because unless it has shut it down this is an error and needs reporting so that something can be done about it.
As such I have a collection of Process which I have started for each I allow them to raise events and then connect to the Exited event.
However the arguments I recieve from this do not tell me which process it is that has exited. Whilst I can wind through the collection of Process objects and check for the one that has exited using the HasExited propert this seem somewhat untidy.
Am I missing somthing in the arguments which I can use or does the exited event simply not report that who has exited

Cheers
Tom



Answer this question

Determining which Process has exited

  • JoeDeVirs

    Doh, of course.

    Thought it must be me missing something.

    Thanks very much.

    Tom


  • Schmidi

    The first argument to your Exited event is the sender of the event. In your case it'll be the process that exited. Therefore cast the first parameter to a Process object and you'll have the information you want.

    void OnProcessExited ( object sender, EventArgs e )
    {
    Process proc = sender as Process;

    //Do your thing
    }

    Michael Taylor - 6/12/06


  • Determining which Process has exited