2 using System
.Threading
;
3 using System
.Collections
;
6 /* each thread will create n domains */
7 static int threads
= 5;
8 static int domains
= 100;
9 static int allocs
= 1000;
11 static int errors
= 0;
13 public static void worker () {
14 Console
.WriteLine ("Domain start " + AppDomain
.CurrentDomain
.FriendlyName
+ " " + Thread
.CurrentThread
.GetHashCode ());
15 ArrayList list
= new ArrayList ();
16 for (int i
= 0; i
< allocs
; ++i
) {
17 list
.Add (new object ());
18 list
.Add (new ArrayList ());
19 list
.Add (new String ('x', 34));
20 int[] a
= new int [5];
21 list
.Add (new WeakReference (a
));
22 if ((i
% 1024) == 0) {
23 list
.RemoveRange (0, list
.Count
/ 2);
26 Console
.WriteLine ("Domain end " + AppDomain
.CurrentDomain
.FriendlyName
+ " " + Thread
.CurrentThread
.GetHashCode ());
29 static void thread_start () {
30 Console
.WriteLine ("Thread start " + Thread
.CurrentThread
.GetHashCode ());
31 for (int i
= 0; i
< domains
; ++i
) {
32 AppDomain appDomain
= AppDomain
.CreateDomain("Test-" + i
);
33 appDomain
.DoCallBack (new CrossAppDomainDelegate (worker
));
35 AppDomain
.Unload (appDomain
);
37 Interlocked
.Increment (ref errors
);
38 Console
.WriteLine ("Error unloading " + "Test-" + i
);
41 Console
.WriteLine ("Thread end " + Thread
.CurrentThread
.GetHashCode ());
43 static int Main (string[] args
) {
45 threads
= int.Parse (args
[0]);
47 domains
= int.Parse (args
[1]);
49 allocs
= int.Parse (args
[2]);
51 loops
= int.Parse (args
[3]);
52 for (int j
= 0; j
< loops
; ++j
) {
53 Thread
[] ta
= new Thread
[threads
];
54 for (int i
= 0; i
< threads
; ++i
) {
55 Thread t
= new Thread (new ThreadStart (thread_start
));
59 for (int i
= 0; i
< threads
; ++i
) {
64 //Console.ReadLine ();