By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,230 Members | 2,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,230 IT Pros & Developers. It's quick & easy.

Exceptions in System.Timers.Timer.Elapsed event are ignored & not reported - desired behaviour?

P: n/a

I was testing this with .NET Framework 2.0.

Exceptions in the Elapsed event handler of a System.Timers.Timer are
ignored, they are not handled by the runtime and not reported (when
running outside of VS.NET) either. Ther Timer continues as if nothing
happened.
Is this the desired behaviour, because this would have very negative
impact on analysis of unexpected errors?
Am i missing any design directives concerining the exception handling
in a System.Timers.Timer object?

The following example demonstrates, what i am speaking of

using System;
using System.Timers;

class TimerTest
{
Timer myTimer;

public TimerTest() {
myTimer = new Timer(1000);
myTimer.Enabled = true;
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
}

void myTimer_Elapsed(object sender, ElapsedEventArgs e) {
Console.WriteLine("TimerTest: Simulate an unexpected exception
....");
// Simulate unexpected exception ...
throw new Exception("Elapsed test exception.");
}
}

class Program
{
static void Main(string[] args) {
TimerTest timerTest = new TimerTest();
Console.WriteLine("TimerTest running. Press any key to
proceed");
Console.Read();
}
}

As already said, the exception is catched inside of VS.NET 2005 by the
Exception Assistant, when debugging.

Thanks & greets
brunft

Dec 14 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.