Created
November 25, 2018 11:57
-
-
Save noseratio/7cacaff95e791932594b16fd02a36ed0 to your computer and use it in GitHub Desktop.
TaskScheduler.UnobservedTaskException - https://stackoverflow.com/a/23505426/1768303
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace UnobservedTaskExceptionDemo | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
TaskScheduler.UnobservedTaskException += (s, e) => | |
{ | |
Console.WriteLine("UnobservedTaskException"); | |
}; | |
Enumerable.Range(1, 10).Select(i => | |
Task.Run(() => { if (i % 2 != 0) throw new InvalidOperationException(); })).ToArray(); | |
Console.WriteLine("Before GC..."); | |
Console.ReadKey(); | |
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, blocking: true); | |
Console.WriteLine("After GC..."); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment