blob: 64be3d00bf12e9fb3a3718e8f6a2710ca1a71ecf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
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");
}
}
|