tags:

views:

185

answers:

1

Is it safe to use System.Threading.Timer in windows service running for a long time?

In other words, is the 49.7 days timer roll-over problem fixed in Windows Server 2003 32bit + .Net Framework 2.0?

Is Thread.Sleep() the only alternative?

Thank you.

+1  A: 

Internal the periods are declared as UInt32, which does have a MaxValue of 4,294,967,295 , or with other words 49.7 days...so I wouldn't trust it to work the right way over such a long period. But, if I look at the reflected code, it should work if you destroy the timer every f.e. 5 days and create a new one.

Edit: As I think about it, Timers and Services don't play well together, you might wanna read this and this.

Bobby
Thank you for your comment, but I would like to have a definite answer. I don't have a possibility to test for 50 days.
John
@Den: that's definite enough. It won't work. If you want to kick off something that infrequently, use scheduled tasks instead of services.
Joel Coehoorn