Okay, you probably all know this, but somewhere someone doesn’t. And I thought it might be a nice article to post. Have you created a Windows Service Timer that isn’t working? The reason for this is because you probably added a Windows Forms Timer to your Service instead of a System Timer. So for future reference, this is what I did:
Windows Service Timer Workaround
In your toolbar, you will see the Timer control under Components. Do not add this timer to your Service. (Why you even can is beyond me. Please, if anyone can provide a reason, leave a comment.) Right click on the toolbar as follows and select Choose Items:
Click on the Namespace Tab to sort the .NET Framework Components.
Scroll down to the System.Timers Namespace and check the check box to the left.
When you return to the Toolbar, you will notice two Timer Controls.
Right Click on each one and Rename the Forms Timer to something like “WinForms Timer” and the Service Timer to “Service Timer”.
Your Toolbox should look as follows.
If you drag an instance of each timer on the Service Designer and select the properties of each, the difference is evident. The Forms timer is a System.Windows.Forms.Timer class and will not work in your Service.
The Service Timer is a System.Timers.Timer class and should be used in your Windows Service.
For more information on using Timers in a Windows Service, take a look at Using Timers in a Windows Service posted by Mark Strawmyer. It is an older post, but I still think that it is relevant and could be a source of useful information. As always, if you have any comments, please consider taking part in the discussion below.