Process.WaitForExit() not working?
have a ASP.NET form that starts an async method that loops through a list of executable files and starts them off
In the button click I call my async method
---------------------------------------------------------------------------------------------------------
startBtchRunD = new StartBatchRunDelegate(StartBatchRun);
startBtchRunD.BeginInvoke(newBatchRunId,DBConnectionString,ExecutableDirectory,new AsyncCallback(this.GoDone),null);
---------------------------------------------------------------------------------------------------------
My method has the following loop
----------------------------------------------------------------------------------------------------------
foreach(Executable exe in Executables)
{
procStartInfo = new ProcessStartInfo(@"c:\windows\system32\wscript.exe",exe.File);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
Process p = new Process();
p = Process.Start(procStartInfo);
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
--------------------------------------------------------------------------------------------------------
For some reason the wait for exit doesn't seem to be doing anything. This loop doesn't wait at all. If I have 4 executables ".vbs" files, they all start pretty much at the same time. Any ideas on why this doesn't seem to be working would be helpful.
I tried to run this from within a windows service and it had the same problem. I must be missing something.
Answers (1)
0 I figured this out... just needed to remove that extra p.Start(); and that was it.. How I missed that.. I don't know. it happens