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
, "Test2");
24 } catch (ThreadAbortException ex
) {
33 public class Test
: MarshalByRefObject
{
34 ThreadAbortException exc
;
35 public JustSomeClass other
;
37 public void doThrow (int n
, object state
) {
39 Thread
.CurrentThread
.Abort (state
);
41 doThrow (n
- 1, state
);
44 public void abortProxy () {
48 public void abortOther () {
49 other
= new JustSomeClass ();
53 public void abortString () {
56 } catch (ThreadAbortException e
) {
61 public void abortOtherIndirect (Test test
) {
65 public object getState () {
66 return exc
.ExceptionState
;
69 public int getInt () {
74 public static class Tests
76 static AppDomain domain
= AppDomain
.CreateDomain ("newdomain");
78 public static int test_0_abort_other_indirect ()
80 Test test
= (Test
) domain
.CreateInstanceAndUnwrap (typeof (Test
).Assembly
.FullName
, typeof (Test
).FullName
);
81 Test testHere
= new Test ();
83 if (!RemotingServices
.IsTransparentProxy (test
)) {
84 Console
.WriteLine ("test is no proxy");
89 test
.abortOtherIndirect (testHere
);
90 } catch (ThreadAbortException e
) {
91 object state
= e
.ExceptionState
;
93 if ((JustSomeClass
)state
!= testHere
.other
) {
94 Console
.WriteLine ("other class not preserved in state");
102 public static int test_0_abort_string ()
104 Test test
= (Test
) domain
.CreateInstanceAndUnwrap (typeof (Test
).Assembly
.FullName
, typeof (Test
).FullName
);
106 if (!RemotingServices
.IsTransparentProxy (test
)) {
107 Console
.WriteLine ("test is no proxy");
113 Console
.WriteLine ("no abort");
115 } catch (ThreadAbortException e
) {
117 state
= e
.ExceptionState
;
118 Thread
.ResetAbort ();
120 Console
.WriteLine ("state is null");
123 if (RemotingServices
.IsTransparentProxy (state
)) {
124 Console
.WriteLine ("state is proxy");
127 if (!((string)state
).Equals ("bla")) {
128 Console
.WriteLine ("state is wrong: " + (string)state
);
132 if (RemotingServices
.IsTransparentProxy (e
)) {
133 Console
.WriteLine ("exception is proxy");
136 if (test
.getState () != null) {
137 Console
.WriteLine ("have state");
145 public static int test_0_abort_proxy ()
147 Test test
= (Test
) domain
.CreateInstanceAndUnwrap (typeof (Test
).Assembly
.FullName
, typeof (Test
).FullName
);
149 if (!RemotingServices
.IsTransparentProxy (test
)) {
150 Console
.WriteLine ("test is no proxy");
156 Console
.WriteLine ("no abort");
158 } catch (ThreadAbortException e
) {
160 state
= e
.ExceptionState
;
161 Thread
.ResetAbort ();
163 Console
.WriteLine ("state is null");
166 if (!RemotingServices
.IsTransparentProxy (state
)) {
167 Console
.WriteLine ("state is not proxy");
170 if (((Test
)state
).getInt () != 123) {
171 Console
.WriteLine ("state doesn't work");
175 if (RemotingServices
.IsTransparentProxy (e
)) {
176 Console
.WriteLine ("exception is proxy");
184 public static int test_0_abort_other ()
186 Test test
= (Test
) domain
.CreateInstanceAndUnwrap (typeof (Test
).Assembly
.FullName
, typeof (Test
).FullName
);
188 if (!RemotingServices
.IsTransparentProxy (test
)) {
189 Console
.WriteLine ("test is no proxy");
195 Console
.WriteLine ("no abort");
197 } catch (ThreadAbortException e
) {
199 bool stateExc
= false;
202 state
= e
.ExceptionState
;
203 Console
.WriteLine ("have state");
204 } catch (Exception
) {
206 /* FIXME: if we put this after the try/catch, mono
208 Thread
.ResetAbort ();
211 Console
.WriteLine ("no state exception");
215 if (RemotingServices
.IsTransparentProxy (e
)) {
216 Console
.WriteLine ("exception is proxy");
224 public static int test_0_abort_in_thread ()
227 // Calling Thread.Abort () from a remoting call throws a ThreadAbortException which
228 // cannot be caught because the exception handling code is confused by the domain
232 Thread thread
= new Thread (delegate () {
233 AppDomain d
= AppDomain
.CreateDomain ("foo");
235 var t
= (Test1
)d
.CreateInstanceAndUnwrap (Assembly
.GetExecutingAssembly().FullName
, "Test1");
248 public static int Main (string [] args
)
250 return TestDriver
.RunTests (typeof (Tests
), args
);