Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. public static void Main()
  2. {
  3. TaskScheduler.UnobservedTaskException += (object sender, UnobservedTaskExceptionEventArgs eventArgs) =>
  4. {
  5. eventArgs.SetObserved();
  6. ((AggregateException)eventArgs.Exception).Handle(ex =>
  7. {
  8. Console.WriteLine("Exception type: {0}", ex.GetType());
  9. return true;
  10. });
  11. };
  12.  
  13. Task.Factory.StartNew(() =>
  14. {
  15. throw new ArgumentNullException();
  16. });
  17.  
  18. Task.Factory.StartNew(() =>
  19. {
  20. throw new ArgumentOutOfRangeException();
  21. });
  22.  
  23.  
  24. Thread.Sleep(100);
  25. GC.Collect();
  26. GC.WaitForPendingFinalizers();
  27.  
  28. Console.WriteLine("Done");
  29. Console.ReadKey();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement