Why an unhandled exception in a timer thread does not crash a process

I know how unpackaged exceptions are handled when using Task s, only throwing the unhandled exceptions into the finalizer if the user code has not "noticed" it yet.

I also know how an unhandled exception in an asynchronous stream (e.g., Action.BeginInvoke() ) is caught and re- Action.EndInvoke() on a connecting call (e.g., Action.EndInvoke() ).

What I do not understand is how it is not a process failure?

  static void Main(string[] args) { var timer = new System.Timers.Timer() {Interval = 100}; timer.Elapsed += (o, e) => { throw new Exception(); }; timer.Start(); Console.ReadKey( true ); } 
+7
source share
1 answer

From the .NET 4.0 documentation:

In the .NET Framework version 2.0 and earlier, the Timer component catches and suppresses all exceptions thrown by event handlers for the Expired Event. This behavior may be changed in future releases of the .NET Framework.

http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx

There is no claim that this behavior has really changed.

+9
source

All Articles