[runtime] Fix DISABLE_REFLECTION_EMIT build.
[mono.git] / mono / tests / appdomain-threadpool-unload.cs
1
2 using System;
3 using System.Linq;
4 using System.Threading;
5
6 class Driver
7 {
8         class ThreadPoolLauncherObject
9         {
10                 public volatile int i = 0;
11
12                 public ThreadPoolLauncherObject ()
13                 {
14                         ThreadPool.QueueUserWorkItem (_ => { for (int i = 0; i < 10 * 1000 * 1000; ++i); }, null);
15                 }
16         }
17
18         public static void Main ()
19         {
20                 int count = 0;
21                 object o = new object ();
22
23                 foreach (var i in
24                         Enumerable.Range (0, 100)
25                                 .AsParallel ().WithDegreeOfParallelism (Environment.ProcessorCount)
26                                 .Select (i => {
27                                         AppDomain ad;
28
29                                         ad = AppDomain.CreateDomain ("testdomain" + i);
30                                         ad.CreateInstance (typeof (ThreadPoolLauncherObject).Assembly.FullName, typeof (ThreadPoolLauncherObject).FullName);
31
32                                         Thread.Sleep (10);
33
34                                         AppDomain.Unload (ad);
35
36                                         return i;
37                                 })
38                                 .Select (i => {
39                                         lock (o) {
40                                                 count += 1;
41
42                                                 Console.Write (".");
43                                                 if (count % 25 == 0)
44                                                         Console.WriteLine ();
45                                         }
46
47                                         return i;
48                                 })
49                 ) {
50                 }
51         }
52 }