Wait For Process to Finish

J

Jordan S

I have written a small Console application that executes the following line,
amongst other things:

System.Diagnostics.Process.Start(currentWorkingDirectory +
@"\backup_files.cmd");

My Console app is NOT waiting for the execution of backup_files.cmd to
finish.

How can I cause my console app to wait for backup_files.cmd to finish before
proceeding?

Thanks!
 
S

Steve Walker

Jordan S <[email protected]> said:
I have written a small Console application that executes the following line,
amongst other things:

System.Diagnostics.Process.Start(currentWorkingDirectory +
@"\backup_files.cmd");

My Console app is NOT waiting for the execution of backup_files.cmd to
finish.

using(Process p = Process.Start(path))
{
while(!p.HasExited)
{
Console.WriteLine("Waiting...");
Thread.Sleep(5000);
}
}
 
L

Lebesgue

You can use p.WaitForExit();

Steve Walker said:
using(Process p = Process.Start(path))
{
while(!p.HasExited)
{
Console.WriteLine("Waiting...");
Thread.Sleep(5000);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top