简体   繁体   中英

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 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!

使用此方法:

process.WaitForExit();

您可以使用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();

在运行下一次迭代之前调用Process.WaitForExit()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM