Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute multiple Process.Start() sequentially in C#

I'm executing 3 exes using Process.Start() in my C# application. I want to run all these exes sequentially. Right now, each Process.Start() executes on its own in a parallel manner.

eg:

Process.Start(exe1ForCopying_A_50_Mb_File);      
Process.Start(exe2ForCopying_A_10_Mb_File);  
Process.Start(exe3ForCopying_A_20_Mb_File);

I want my 2nd Process.Start() to start executing ONLY AFTER first Process.Start() has finished copying the 50 Mb file (which would be taking around 1 or 2 minutes).

Any suggestions?

Thanks.

like image 788
Sandeep Avatar asked Dec 09 '22 08:12

Sandeep


1 Answers

I think I got the answer myself..! :)

Process process = new Process(); 
ProcessStartInfo startInfo = new ProcessStartInfo(); 
startInfo.FileName = MyExe; 
startInfo.Arguments = ArgumentsForMyExe; 
process.StartInfo = startInfo; 
process.Start(); 
process.WaitForExit(); // This is the line which answers my question :) 

Thanks for the suggestion VAShhh..

like image 108
Sandeep Avatar answered Dec 11 '22 23:12

Sandeep