Search code examples
c#tasktopshelf

Unobserved task exception handling with TopShelf


I am using TopShelf framework which is just working great. However I am having great trouble figuring out how to register a top level exception filter for unobserved task exceptions (i.e subscribing to TaskScheduler.UnobservedTaskException).

I tried different places to register to this event, but no matter what, I never get the notification when I throw exceptions from non awaited tasks.

How can I correctly get these notifications when using TopShelf.

Thanks.


Solution

  • My bad,

    It had nothing related to TopShelf but to the behavior of TaskScheduler.UnobservedTaskException which must wait for the exception throwing task to be garbage collected before getting the exception :(