2 using System
.Threading
;
3 using System
.Runtime
.Remoting
;
5 // Does a foreign domain's thread object persist (in .NET) even if it
6 // hasn't been started?
8 // Insubstantial, because it can't be "moved" to another domain.
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)?
13 // No, we can't start it from another domain, because we can't bring
16 // What if we start a foreign domain's thread if the domain is gone?
20 public class Test
: MarshalByRefObject
{
24 public void setThread () {
25 Console
.WriteLine ("setting thread");
26 thread
= Thread
.CurrentThread
;
30 public void setStr (string s
) {
31 Console
.WriteLine ("setting str");
35 public void callSetThread (Test t
) {
36 Thread thread
= new Thread (new ThreadStart (t
.setThread
));
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
);
51 otherTest
.callSetThread (myTest
);
53 if (myTest
.thread
.GetType () == Thread
.CurrentThread
.GetType ())
54 Console
.WriteLine ("same type");
56 Console
.WriteLine ("different type");
60 AppDomain
.Unload (domain
);
63 GC
.WaitForPendingFinalizers ();
65 Console
.WriteLine ("thread " + myTest
.thread
);
67 Console
.WriteLine ("str " + myTest
.str
);
69 if (!myTest
.thread
.Name
.Equals("foo"))