Reputation: 438
I'm running a batch file using Process. The problem is I want the batch file to finish its execution and then the next set of lines should be executed. Here's the code snippet.
Process proc = new Process();
proc.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + sFileName+".bat";
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
Thread.Sleep(1000);
// Method which will be executed after the batch file
Method1();
Method1() should execute only when the batch file has completed its execution.
Can anyone please help?
Upvotes: 1
Views: 1739
Reputation: 150238
You can simply call
proc.WaitForExit();
Method1();
Instructs the Process component to wait the specified number of milliseconds for the associated process to exit.
https://msdn.microsoft.com/en-us/library/ty0d8k56.aspx
Note there is no need for your
Thread.Sleep(1000);
Upvotes: 4