I am trying to understand the UnobservedTaskException issue 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 fired and then my app just keeps working. However according to MSDN the process should be killed. Can anyone tell me why ?