[2019-12] [threads] Add back mono_threads_attach_tools_thread as a public API (#18074)
[mono-project.git] / mono / tests / threadpool-exceptions5.cs
blob945866169fdae41b8dc997733a3eaf278d9f7c57
1 using System;
2 using System.Threading;
4 class Test {
6 static ManualResetEvent mre = new ManualResetEvent (false);
8 static int Main ()
10 AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
11 WaitCallback wcb = new WaitCallback ((a) => {
12 Thread.CurrentThread.Abort();
13 });
15 wcb.BeginInvoke (wcb, OnCBFinished, null);
17 if (!mre.WaitOne (10000))
18 return 2;
20 GC.Collect ();
21 GC.WaitForPendingFinalizers ();
23 /* expected exit code: 255 */
24 Thread.Sleep (10000);
25 return 0;
28 static void OnUnhandledException (object sender, UnhandledExceptionEventArgs e)
30 string str = e.ExceptionObject.ToString ();
31 if (!str.Contains ("From OnCBFinished")) {
32 Environment.Exit (3);
33 return;
36 if (!e.IsTerminating) {
37 Environment.Exit (4);
38 return;
41 mre.Set ();
44 static void OnCBFinished (object arg)
46 throw new Exception ("From OnCBFinished");