当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - 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?

网友答案:

After your Start() call, add: use Process.WaitForExit()

 var myProcess = new Process {StartInfo = new ProcessStartInfo(processPath)};
   myProcess.Start();
   myProcess.WaitForExit();
网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: