Tags: | Categories: Blog Posted by admin on 3/9/2009 5:54 PM | Comments (4)

Once again after a year I found code for a windows service using System.Timers.Timer, and guess what, it does not work ... again ... duh. So after all these resources telling you, don't do it:

http://discuss.develop.com/archives/wa.exe?A2=ind0306D&L=DOTNET-CLR&P=R1007&D=0&I=-3

http://discuss.develop.com/archives/wa.exe?A2=ind0309D&L=DOTNET-CLR&P=R5347&I=-3

There are people that still use it for services. To all this people, please use System.Threading.Timer in 2.0 don't do it in 1.1. I believe there is still a bug assign to that one:

http://support.microsoft.com/?id=900822

Also, please rememeber that System.Threading.Timer  is not thread safe, even being on the Threading namespace is not thread safe, so real this awesome article from Alex Calvo for a safe service programming ;-)

http://msdn.microsoft.com/msdnmag/issues/04/02/TimersinNET/default.aspx

Hope this helps people to debug why their service stops calling the TimeElapsed function and why is not every X seconds.

Cheers

Al

blog comments powered by Disqus