I am having troubles with a background worker that will have processes running. If the last process started on the background worker completes it calls the RunWorkComplete d method, even if all of the processes aren't complete. I want to start all of the processes at once, and wait until all are finished before it is complete:
Code:
private void TestRunning_DoWork(object sender, DoWorkEventArgs e)
{
procIDs = new int[CHKD];
int counter = 0;
foreach (TreeNode exe in myqueue)
{
string exe2 = (string)exe.Text;
string FullPath = "";
//Make the tests run in background so the app doesn't pause
{
var TestSettings = new ProcessStartInfo(exe2, RunTestBuilder);
TestSettings.RedirectStandardOutput = false;
TestSettings.UseShellExecute = true;
TestSettings.CreateNoWindow = true;
TestSettings.WindowStyle = ProcessWindowStyle.Minimized;
if (exe.Parent == null)
{
FullPath = di.ToString();
}
else
{
FullPath = di.ToString() + "\\" + exe.Parent.Text;
}
TestSettings.WorkingDirectory = FullPath;
RunTests = new Process();
RunTests.StartInfo = TestSettings;
RunTests.Start();
procIDs[counter] = RunTests.Id;
appID = RunTests.SessionId;
counter++;
}
}
RunTests.WaitForExit();
if (TestRunning.CancellationPending)
{
e.Cancel = true;
return;
}
}