[interp] disable assemblyresolve_event6.exe
[mono.git] / mono / tests / process-leak.cs
1 using System;
2 using System.Diagnostics;
3 using System.Reflection;
4
5
6 namespace ToManyOpenHandles
7 {
8         class Program
9         {
10                 static void Main(string[] args)
11                 {
12                         if (args.Length >= 1)
13                         {
14                                 WriteStuffMode(args[0]);
15                                 return;
16                         }
17
18                         RunStuffMode();
19
20                         Console.WriteLine("Success!!!!");
21                 }
22
23                 private static void WriteStuffMode(string counter)
24                 {
25                         Console.WriteLine("Run {0} {1}", counter, Console.ReadLine ());
26                 }
27
28                 private static void RunStuffMode()
29                 {
30                         for (int i = 0; i < 100; i++)
31                         {
32                                 Execute(Assembly.GetExecutingAssembly().Location, i.ToString());
33                         }
34                 }
35
36                 public static void Execute(string exe, string exeArgs)
37                 {
38                         using (var p = NewProcess(exe, exeArgs))
39                         {
40                                 p.OutputDataReceived += (sender, args) =>
41                                 {
42                                         if (args.Data != null)
43                                                 Console.WriteLine(args.Data);
44                                 };
45                                 p.ErrorDataReceived += (sender, args) =>
46                                 {
47                                         if (args.Data != null)
48                                                 Console.Error.WriteLine(args.Data);
49                                 };
50
51                                 p.Start();
52                                 p.BeginOutputReadLine();
53                                 p.BeginErrorReadLine();
54
55                                 p.StandardInput.WriteLine ("hello");
56
57                                 p.WaitForExit();
58                                 p.CancelErrorRead();
59                                 p.CancelOutputRead();
60
61                                 GC.Collect ();
62                         }
63                 }
64
65                 public static Process StartProcess(string filename, string arguments)
66                 {
67                         var p = NewProcess(filename, arguments);
68
69                         p.Start();
70                         return p;
71                 }
72
73                 static Process NewProcess(string exe, string args)
74                 {
75                         var p = new Process
76                         {
77                                 StartInfo =
78                                 {
79                                         Arguments = args,
80                                         CreateNoWindow = true,
81                                         UseShellExecute = false,
82                                         RedirectStandardOutput = true,
83                                         RedirectStandardInput = true,
84                                         RedirectStandardError = true,
85                                         FileName = exe,
86                                 }
87                         };
88
89                         return p;
90                 }
91         }
92 }