[runtime] Fix DISABLE_REFLECTION_EMIT build.
[mono.git] / mono / tests / xdomain-threads.cs
1 using System;
2 using System.Threading;
3 using System.Runtime.Remoting;
4
5 // Does a foreign domain's thread object persist (in .NET) even if it
6 // hasn't been started?
7 //
8 // Insubstantial, because it can't be "moved" to another domain.
9
10 // Can we start a foreign domain's thread (i.e. does the thread then
11 // switch to the foreign domain and execute the start method there)?
12 //
13 // No, we can't start it from another domain, because we can't bring
14 // to another domain.
15
16 // What if we start a foreign domain's thread if the domain is gone?
17 //
18 // See above.
19
20 public class Test : MarshalByRefObject {
21     public Thread thread;
22     public String str;
23
24     public void setThread () {
25         Console.WriteLine ("setting thread");
26         thread = Thread.CurrentThread;
27         thread.Name = "foo";
28     }
29
30     public void setStr (string s) {
31         Console.WriteLine ("setting str");
32         str = s;
33     }
34
35     public void callSetThread (Test t) {
36         Thread thread = new Thread (new ThreadStart (t.setThread));
37
38         thread.Start ();
39         thread.Join ();
40
41         t.setStr ("a" + "b");
42     }
43 }
44
45 public class main {
46     public static int Main (string [] args) {
47         AppDomain domain = AppDomain.CreateDomain ("newdomain");
48         Test myTest = new Test ();
49         Test otherTest = (Test) domain.CreateInstanceAndUnwrap (typeof (Test).Assembly.FullName, typeof (Test).FullName);
50
51         otherTest.callSetThread (myTest);
52
53         if (myTest.thread.GetType () == Thread.CurrentThread.GetType ())
54                 Console.WriteLine ("same type");
55         else {
56                 Console.WriteLine ("different type");
57                 return 1;
58         }
59
60         AppDomain.Unload (domain);
61
62         GC.Collect ();
63         GC.WaitForPendingFinalizers ();
64
65         Console.WriteLine ("thread " + myTest.thread);
66
67         Console.WriteLine ("str " + myTest.str);
68
69         if (!myTest.thread.Name.Equals("foo"))
70                 return 1;
71
72         return 0;
73     }
74 }