public void RegisterRunning(TreeTask <TBb> task) { CurrentlyRunning.Add(task); // We remove it here to spare some cycles later on. if (task.PreviousTickState == TaskState.Running) { PreviouslyRunning.Remove(task); } // The first one to report running is the deepest running one if (RunningTask == null) { RunningTask = task; } }
public void Run() { /* * FileInfo exeFileInfo = new FileInfo(exefile); * if(!exeFileInfo.Exists) { * Console.Error.WriteLine("unable to find file: '" + exeFileInfo.FullName + "'"); * return; * } * psi.FileName = exeFileInfo.FullName; * psi.WorkingDirectory = exeFileInfo.DirectoryName; */ ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = this.exefile; psi.Arguments = this.args; psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; Console.WriteLine("starting case {0} (exe '{1}' args '{2}')...", i + 1, psi.FileName, psi.Arguments); lock (synclock) { CurrentlyRunning.Add(i); } using (var stdout = new StreamWriter("out_" + (i + 1) + ".txt")) { using (var p = new Process()) { p.StartInfo = psi; DataReceivedEventHandler handler = delegate(object sender, DataReceivedEventArgs e) { try { stdout.WriteLine(e.Data); stdout.Flush(); } catch (Exception ee) { Console.WriteLine("FAILED " + (i + 1) + ": " + ee.Message + " (" + ee.GetType().FullName + ")"); throw; } return; }; p.OutputDataReceived += handler; p.ErrorDataReceived += handler; try { p.Start(); p.BeginErrorReadLine(); p.BeginOutputReadLine(); p.WaitForExit(); success = (p.ExitCode == 0); stdout.Flush(); Console.WriteLine("finished " + (i + 1) + ", exit code " + p.ExitCode); } catch (Exception e) { Console.WriteLine("FAILED " + (i + 1) + ": " + e.Message + " (" + e.GetType().FullName + ")"); stdout.WriteLine("FAILED " + (i + 1) + ": " + e.Message + " (" + e.GetType().FullName + ")"); success = false; } } stdout.Flush(); } int[] running; lock (synclock) { CurrentlyRunning.Remove(i); running = CurrentlyRunning.ToArray(); Console.Write("Currently running:"); foreach (int j in running) { Console.Write(" " + (j + 1)); } Console.WriteLine(";"); } Console.Out.Flush(); }