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

Exceptions in timers

P: n/a
Hi all,

What would happen if I let an exception escape a timer thread, as in the
following example. Would the behaviour be any different when done from a
timer that is synchronized with a Form (so SynchronizingObject = Form
instance)? Is there any difference in behaviour when comparing 1.1 vs 2.0?

using System.Timers;
class Bar
{
private System.Timers.Timer bazTimer;

public void Foo( )
{
bazTimer = new System.Timers.Timer( );
bazTimer.AutoReset = true;
bazTimer.Interval = 1000;
bazTimer.SynchronizingObject = null; // threadpool
bazTimer.Elapsed += new ElapsedEventHandler( TimeThis );
bazTimer.Enabled = true;
}

private void TimeThis( )
{
throw new InvalidOperationException( );
}

[STAThread]
static void Main( )
{
Bar b = new Bar( );
b.Foo( );
System.Threading.Thread.Sleep( 100000 );
}
}

Kind Regards,
--
Tom Tempelaere.
Oct 16 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.