Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / unhandled-exception-7.cs
1 using System;
2 using System.Diagnostics;
3 using System.Threading;
4 using System.Threading.Tasks;
5 using System.Runtime.Remoting.Messaging;
6
7 class CustomException : Exception
8 {
9 }
10
11 class CrossDomain : MarshalByRefObject
12 {
13         public Action NewDelegateWithTarget ()
14         {
15                 return new Action (Bar);
16         }
17
18         public Action NewDelegateWithoutTarget ()
19         {
20                 return () => { throw new CustomException (); };
21         }
22
23         public void Bar ()
24         {
25                 throw new CustomException ();
26         }
27 }
28
29 class Driver
30 {
31         /* expected exit code: 255 */
32         static void Main (string[] args)
33         {
34                 if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
35                         AppDomain.CurrentDomain.UnhandledException += (s, e) => {};
36
37                 ManualResetEvent mre = new ManualResetEvent (false);
38
39                 var ad = AppDomain.CreateDomain ("ad");
40
41                 if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
42                         ad.UnhandledException += (s, e) => {};
43
44                 var cd = (CrossDomain) ad.CreateInstanceAndUnwrap (typeof(CrossDomain).Assembly.FullName, "CrossDomain");
45
46                 var action = cd.NewDelegateWithoutTarget ();
47                 var ares = action.BeginInvoke (Callback, null);
48
49                 Thread.Sleep (5000);
50
51                 Environment.Exit (1);
52         }
53
54         static void Callback (IAsyncResult iares)
55         {
56                 ((Action) ((AsyncResult) iares).AsyncDelegate).EndInvoke (iares);
57         }
58 }