[Microsoft.Build] Ignore ThreadAbortException in BuildNodeManager
[mono-project.git] / mono / tests / process-leak.cs
blob69a2ecf43341d8da6b5e9f3acfb59093e6157cb1
1 using System;
2 using System.Diagnostics;
3 using System.Reflection;
6 namespace ToManyOpenHandles
8 class Program
10 static void Main(string[] args)
12 if (args.Length >= 1)
14 WriteStuffMode(args[0]);
15 return;
18 RunStuffMode();
20 Console.WriteLine("Success!!!!");
23 private static void WriteStuffMode(string counter)
25 Console.WriteLine("Run {0} {1}", counter, Console.ReadLine ());
28 private static void RunStuffMode()
30 for (int i = 0; i < 100; i++)
32 Execute(Assembly.GetExecutingAssembly().Location, i.ToString());
36 public static void Execute(string exe, string exeArgs)
38 using (var p = NewProcess(exe, exeArgs))
40 p.OutputDataReceived += (sender, args) =>
42 if (args.Data != null)
43 Console.WriteLine(args.Data);
45 p.ErrorDataReceived += (sender, args) =>
47 if (args.Data != null)
48 Console.Error.WriteLine(args.Data);
51 p.Start();
52 p.BeginOutputReadLine();
53 p.BeginErrorReadLine();
55 p.StandardInput.WriteLine ("hello");
57 p.WaitForExit();
58 p.CancelErrorRead();
59 p.CancelOutputRead();
61 GC.Collect ();
65 public static Process StartProcess(string filename, string arguments)
67 var p = NewProcess(filename, arguments);
69 p.Start();
70 return p;
73 static Process NewProcess(string exe, string args)
75 var p = new Process
77 StartInfo =
79 Arguments = args,
80 CreateNoWindow = true,
81 UseShellExecute = false,
82 RedirectStandardOutput = true,
83 RedirectStandardInput = true,
84 RedirectStandardError = true,
85 FileName = exe,
89 return p;