I am trying to understand the UnobservedTaskException problem in .NET 4.0, so I wrote the folloging code
TaskScheduler.UnobservedTaskException += (sender, eventArgs) => Console.WriteLine("unobserved"); Task.Factory.StartNew(() => { throw new Exception(); }, TaskCreationOptions.LongRunning); using (var autoResetEvent = new AutoResetEvent(false)) { autoResetEvent.WaitOne(TimeSpan.FromSeconds(10)); } Console.WriteLine("Collecting"); GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine("Still working "); Console.ReadKey(); Console.WriteLine("Still working "); Console.WriteLine("Still working "); Console.ReadKey();
UnobservedTaskException is thrown, and my application just continues to work. However, according to MSDN, the process must be killed. Can someone tell me why?
source share