2 using System
.Threading
;
3 using System
.Runtime
.Remoting
;
4 using System
.Reflection
;
6 public class JustSomeClass
{
9 public class Test2
: ContextBoundObject
12 Thread
.CurrentThread
.Abort ();
16 public class Test1
: MarshalByRefObject
19 AppDomain d
= AppDomain
.CreateDomain ("foo2");
21 var t2
= (Test2
)d
.CreateInstanceAndUnwrap (Assembly
.GetExecutingAssembly().FullName
,
25 } catch (ThreadAbortException ex
) {
34 public class Test
: MarshalByRefObject
{
35 ThreadAbortException exc
;
36 public JustSomeClass other
;
38 public void doThrow (int n
, object state
) {
40 Thread
.CurrentThread
.Abort (state
);
42 doThrow (n
- 1, state
);
45 public void abortProxy () {
49 public void abortOther () {
50 other
= new JustSomeClass ();
54 public void abortString () {
57 } catch (ThreadAbortException e
) {
62 public void abortOtherIndirect (Test test
) {
66 public object getState () {
67 return exc
.ExceptionState
;
70 public int getInt () {
76 public static int Main (string [] args
) {
77 AppDomain domain
= AppDomain
.CreateDomain ("newdomain");
78 Test test
= (Test
) domain
.CreateInstanceAndUnwrap (typeof (Test
).Assembly
.FullName
, typeof (Test
).FullName
);
80 Test testHere
= new Test ();
82 if (!RemotingServices
.IsTransparentProxy (test
)) {
83 Console
.WriteLine ("test is no proxy");
88 test
.abortOtherIndirect (testHere
);
89 } catch (ThreadAbortException e
) {
90 object state
= e
.ExceptionState
;
92 if ((JustSomeClass
)state
!= testHere
.other
) {
93 Console
.WriteLine ("other class not preserved in state");
101 } catch (ThreadAbortException e
) {
103 state
= e
.ExceptionState
;
104 Thread
.ResetAbort ();
107 Console
.WriteLine ("state is null");
110 if (RemotingServices
.IsTransparentProxy (state
)) {
111 Console
.WriteLine ("state is proxy");
114 if (!((string)state
).Equals ("bla")) {
115 Console
.WriteLine ("state is wrong: " + (string)state
);
119 if (RemotingServices
.IsTransparentProxy (e
)) {
120 Console
.WriteLine ("exception is proxy");
123 if (test
.getState () != null) {
124 Console
.WriteLine ("have state");
129 Console
.WriteLine ("no abort");
136 } catch (ThreadAbortException e
) {
138 state
= e
.ExceptionState
;
139 Thread
.ResetAbort ();
142 Console
.WriteLine ("state is null");
145 if (!RemotingServices
.IsTransparentProxy (state
)) {
146 Console
.WriteLine ("state is not proxy");
149 if (((Test
)state
).getInt () != 123) {
150 Console
.WriteLine ("state doesn't work");
154 if (RemotingServices
.IsTransparentProxy (e
)) {
155 Console
.WriteLine ("exception is proxy");
160 Console
.WriteLine ("no abort");
167 } catch (ThreadAbortException e
) {
169 bool stateExc
= false;
174 state
= e
.ExceptionState
;
175 Console
.WriteLine ("have state");
176 } catch (Exception
) {
178 /* FIXME: if we put this after the try/catch, mono
180 Thread
.ResetAbort ();
183 Console
.WriteLine ("no state exception");
187 if (RemotingServices
.IsTransparentProxy (e
)) {
188 Console
.WriteLine ("exception is proxy");
193 Console
.WriteLine ("no abort");
198 // Calling Thread.Abort () from a remoting call throws a ThreadAbortException which
199 // cannot be caught because the exception handling code is confused by the domain
203 Thread thread
= new Thread (delegate () {
204 AppDomain d
= AppDomain
.CreateDomain ("foo");
206 var t
= (Test1
)d
.CreateInstanceAndUnwrap (Assembly
.GetExecutingAssembly().FullName
,
217 Console
.WriteLine ("done");