Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 983
NwkProg Avatar asked Jan 19 '23 23:01

NwkProg


2 Answers

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.

like image 122
Franci Penov Avatar answered Jan 30 '23 00:01

Franci Penov


You can listen to the Exited event (you have to make sure EnableRaisingEvents is true).

like image 30
Austin Salonen Avatar answered Jan 29 '23 23:01

Austin Salonen