Is there a way to iterate through an array/list and launch a process, and wait until it’s exited until launching the next, and so on?
I have the code:
string[] processPaths = new string[]{ @"c:\foo.exe", @"c:\bar.exe" };
foreach(string s in processPaths){
Process p = new Process();
p.Exited += (obj, ev) => { continue; };
}
but obviously processes are executed asynchronously and the lambda function isn’t part of the foreach loop. It’s a console application, and I don’t mind if it runs on the main thread.
Process.WaitForExit()is what you are looking for.