Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / threadpool-exceptions5.cs
1 using System;
2 using System.Threading;
3
4 class Test {
5         static object monitor;
6         static int return_value = 2;
7         static int Main ()
8         {
9                 monitor = new object ();
10                 AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
11                 WaitCallback wcb = new WaitCallback ((a) => {
12                         Thread.CurrentThread.Abort();
13                 });
14                 wcb.BeginInvoke (wcb, OnCBFinished, null);
15                 lock (monitor) {
16                         Monitor.Wait (monitor);
17                 }
18                 Thread.Sleep (1000);
19                 return 1;
20         }
21
22         static void OnUnhandledException (object sender, UnhandledExceptionEventArgs e)
23         {
24                 string str = e.ExceptionObject.ToString ();
25                 if (str.IndexOf ("From the threadpool") != -1)
26                         return_value = 3;
27                 lock (monitor) {
28                         Monitor.Pulse (monitor);
29                 }
30                 Environment.Exit (return_value);
31         }
32
33         static void OnCBFinished (object arg)
34         {
35                 return_value = 0;
36                 throw new Exception ("From OnCBFinished");
37         }
38 }
39