开发者

How do I force Process.Start() to complete before proceeding?

I'm creating a console app to process a file and then move it to a 'processed' folder. The main console app 开发者_JAVA百科calls another app using Process.Start(). This secondary app actually does the work of bulk inserting data into a database. Once the bulk insert is complete, the main app will move the file to another folder and then move on to additional tasks.

In the main app, how do I prevent the code from continuing until the secondary app finishes? I really need to have the first process finish before moving on to the next step.

Thanks!


Use this method:

process.WaitForExit();


You can use the WaitForExit() Methode


You might try:

Process.Start(...).WaitForExit();

Presuming you are using ProcessStartInfo, you might write it more like this:

var psi = new ProcessStartInfo();
psi.FileName = "SecondProcess.exe";
psi.Arguments = "arg1 arg2";
var process = Process.Start(psi);
if(process != null) process.WaitForExit();


See the following links:

http://support.microsoft.com/kb/305368

http://www.monkeycancode.com/c-run-process-wait-for-it-to-finish


Call Process.WaitForExit() before running the next iteration.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜