Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I start a new Process and wait until it finishes?

I want to start a program with C# (could use Process.Start()). Then my program should wait until the started program is closed, before it continues.
How do I do this?

like image 714
Paedow Avatar asked Feb 04 '13 17:02

Paedow


2 Answers

After you call Start() add: Process.WaitForExit()

 var myProcess = new Process {StartInfo = new ProcessStartInfo(processPath)};
 myProcess.Start().WaitForExit();
like image 103
Cédric Bignon Avatar answered Oct 19 '22 23:10

Cédric Bignon


There are two mechanism. You can either hook the Process.Exited event or what you probably really want is to call Process.WaitForExit().

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.exited.aspx

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.waitforexit.aspx

like image 36
Phillip Scott Givens Avatar answered Oct 19 '22 23:10

Phillip Scott Givens