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

46 lines
799 B
C#

using System;
using System.Threading;
using System.Threading.Tasks;
class X
{
static bool unobserved;
public static int Main ()
{
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
try {
Test ().Wait ();
GC.Collect ();
GC.WaitForPendingFinalizers ();
if (unobserved)
return 1;
return 0;
} finally {
TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException;
}
}
static void TaskScheduler_UnobservedTaskException (object sender, UnobservedTaskExceptionEventArgs e)
{
unobserved = true;
Console.WriteLine ("unobserved");
}
static async Task Test ()
{
try {
await ThrowAsync ();
} catch {
}
}
static async Task ThrowAsync()
{
await Task.Delay (5);
throw new Exception ("boom");
}
}