linux-packaging-mono/mcs/tests/test-async-19.cs
Jo Shields 8b9b85e7f5 Imported Upstream version 3.10.0
Former-commit-id: 172c8e3c300b39d5785c7a3e8dfb08ebdbc1a99b
2014-10-04 11:27:48 +01:00

44 lines
921 B
C#

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 ();
}
}