I am currently tasked with creating a Job Scheduler windows service and have been doing some threading research. I have come to the conclusion that I will be using a Timer to trigger when the next job is to get fired off. (there are plenty of issues in addition to be dealt with here that I will not mention: cache updating, synchronization issues, etc...). .NET has 3 native timer classes as described below. After reading some information from others who have tried unsucessfully to implement Systm.Timers.Timer in a windows service, I have decided to go with the System.Threading.Timer. I will already be dealing with plenty of threading and synchronization issues, so I would like to limit the possibility of chasing down other problems. The System.Threading.Timer is lighter weight than the System.Timers.Timer, however, the System.Timers.Timer has some nice features, such as, the adding/removing of listeners after the timer has been instantiated. I can see why others decided to try to use it in their services.
| Feature description |
System.Timers.Timer |
System.Threading.Timer |
System.Windows.Forms.Timer |
| Support for adding and removing listeners after the timer is instantiated. |
Yes |
No |
Yes |
| Supports call backs on the user-interface thread |
Yes |
No |
Yes |
| Calls back from threads obtained from the thread pool |
Yes |
Yes |
No |
| Supports drag-and-drop in the Windows Forms Designer |
Yes |
No |
Yes |
| Suitable for running in a server multi-threaded environment |
Yes |
Yes |
No |
| Includes support for passing arbitrary state from the timer initialization to the callback. |
No |
Yes |
No |
| Implements IDisposable |
Yes |
Yes |
Yes |
| Supports one-off callbacks as well as periodic repeating callbacks |
Yes |
Yes |
Yes |
| Accessible across application domain boundaries |
Yes |
Yes |
Yes |
| Supports IComponent – hostable in an IContainer |
Yes |
No |
Yes |