[tests] Add tests for AppDomainUnloadedException handling
[mono.git] / mono / tests / appdomain-unload-exception.cs
1 using System;
2 using System.Diagnostics;
3 using System.Threading;
4 using System.Threading.Tasks;
5
6 class Driver
7 {
8         static void ThrowTP ()
9         {
10                 ManualResetEvent mre = new ManualResetEvent (false);
11
12                 ThreadPool.QueueUserWorkItem (_ => { try { throw new AppDomainUnloadedException (); } finally { mre.Set (); } });
13
14                 if (!mre.WaitOne (5000))
15                         Environment.Exit (1);
16
17                 /* Wait for exception unwinding */
18                 Thread.Sleep (500);
19         }
20
21         static void ThrowThread ()
22         {
23                 Thread thread = new Thread (_ => { throw new AppDomainUnloadedException (); });
24                 thread.Start ();
25                 thread.Join ();
26         }
27
28         static int Main (string[] args)
29         {
30                 ThrowTP ();
31                 ThrowThread ();
32
33                 return 0;
34         }
35 }