3 using System.Diagnostics;
5 using System.Threading;
6 using System.Threading.Tasks;
12 Action<Process>[] tests = new Action<Process> [] {
13 new Action<Process> (Test1),
14 new Action<Process> (Test2),
17 ProcessStartInfo psi = new ProcessStartInfo () {
20 UseShellExecute = false,
21 RedirectStandardOutput = true,
24 foreach (Action<Process> test in tests) {
25 for (int i = 0; i < 500; ++i) {
26 test (new Process () { StartInfo = psi });
31 static void Test1 (Process p)
33 StringBuilder sb = new StringBuilder ();
34 ManualResetEvent mre_exit = new ManualResetEvent (false);
35 ManualResetEvent mre_output = new ManualResetEvent (false);
37 p.EnableRaisingEvents = true;
38 p.Exited += (s, a) => mre_exit.Set ();
42 p.OutputDataReceived += (s, a) => {
50 p.BeginOutputReadLine ();
52 if (!mre_exit.WaitOne (1000))
54 if (!mre_output.WaitOne (1000))
57 if (sb.ToString () != "hello") {
58 Console.WriteLine ("process output = '{0}'", sb.ToString ());
63 static void Test2 (Process p)
65 StringBuilder sb = new StringBuilder ();
66 ManualResetEvent mre_output = new ManualResetEvent (false);
70 p.OutputDataReceived += (s, a) => {
79 p.BeginOutputReadLine ();
81 if (!p.WaitForExit (1000))
83 if (!mre_output.WaitOne (1000))
86 if (sb.ToString () != "hello") {
87 Console.WriteLine ("process output = '{0}'", sb.ToString ());