Problem with Process.HasExited
-
Using a windows app to batch run a DOS program. Need to wait until the DOS app has finished before going on with the next file. Using:
Process.Start(thecommand, thearguments);
System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
while (!p.HasExited)
{
aaa=5;
}but it seems to be waiting for my windows app to end, not the DOS app. I can see my DOS app running in a DOS window, and it closes when finished (it takes about a minute to run), but my app sits there in the while loop. I put a breakpoint at
aaa = 5;
and the app definitely sits in that loop. -
Using a windows app to batch run a DOS program. Need to wait until the DOS app has finished before going on with the next file. Using:
Process.Start(thecommand, thearguments);
System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
while (!p.HasExited)
{
aaa=5;
}but it seems to be waiting for my windows app to end, not the DOS app. I can see my DOS app running in a DOS window, and it closes when finished (it takes about a minute to run), but my app sits there in the while loop. I put a breakpoint at
aaa = 5;
and the app definitely sits in that loop. -
Uh, that's because you're assigning p to the current process, i.e. the one you are running! I think you want
Process p = Process.Start(thecommand, thearguments);
I must have misunderstood the examples in the answers to other similar questions!! Working now.