linux-packaging-mono/mcs/tests/test-async-19.cs
Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

46 lines
963 B
C#

// Compiler options: -langversion:future
using System;
using System.Threading;
using System.Threading.Tasks;
class C
{
static ManualResetEvent caught = new ManualResetEvent (false);
static async void Test (ManualResetEvent mre)
{
var a = Task.Factory.StartNew (() => {
if (mre.WaitOne (1000))
throw new ApplicationException ();
});
await a.ConfigureAwait (false);
}
public static int Main ()
{
ManualResetEvent mre = new ManualResetEvent (false);
Test (mre);
var handler = new UnhandledExceptionEventHandler (CurrentDomain_UnhandledException);
AppDomain.CurrentDomain.UnhandledException += handler;
try {
mre.Set ();
if (!caught.WaitOne (1000))
return 1;
return 0;
} finally {
AppDomain.CurrentDomain.UnhandledException -= handler;
}
}
static void CurrentDomain_UnhandledException (object sender, UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject is ApplicationException)
caught.Set ();
}
}