The document states that:
The timer component captures and suppresses all exception handlers for the Elapsed event.
You need to catch the method OnTimedEventand then throw this exception, for example, throwing it into another thread if you want to CurrentDomain_UnhandledExceptioncatch it ( throwin ThreadPool.QueueUserWorkItem())
Alternatively create a handler:
private static void TimerExceptionHandler(Exception ex)
{
Console.WriteLine(ex.ToString());
...
}
ElapsedEventHandler:
aTimer.Elapsed += (sender, e) => { OnTimedEvent(sender, e, TimerExceptionHandler); };
, :
private static void OnTimedEvent(object source, ElapsedEventArgs e, Action<Exception> timerExceptionHandler)
try
{
RunTests();
}
catch (Exception ex)
{
timerExceptionHandler(ex);
}