Wait For Process to Finish

  • Thread starter Thread starter Jordan S
  • Start date Start date
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!
 
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);
}
}
 
You can use p.WaitForExit();

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