Search code examples
c#windowsformsprocess.start

Handling Closing of Multiple Processes


Here's what I'm doing. I have a loop that fires 20 processes using Process.Start(). I want them all to fire at once, however I want to catch them as they close. Is there anyway to do this in C#?

I know you can do process.WaitForExit(), but then all of them don't fire at once (which is what I want it to do). Basically, I want to know when certain processes end so I can inform the user by updating database records, so they can know when certain processes have finished. As opposed to just trying to keep track of them as they close and changing the ProcessWindowStyle to normal.

Many thanks.


Solution

  • Set Process.EnableRaisingEvents to true, and subscribe to the Exited event.

    An alternative is to have a timer on which you check the HasExited property.