Server timers are a different creature than dormant threads.
On the one hand, depending on the priority of your thread and what else works, your sleep thread may or may not be awakened and scheduled to run at the interval you requested. If the interval is long enough and scheduling accuracy is not a big deal, Thread.Sleep() is the smart choice.
Timers, on the other hand, can create their own events in any thread, which improves planning capabilities. The cost of using timers, however, is a bit more complicated in your code - and the fact that you cannot control which thread executes the logic in which the timer event fires. From the docs:
The server timer is designed to be used with workflows in a multi-threaded environment. server timers can move between threads to handle the raised Expired event, which leads to greater accuracy than Windows Timers when increasing time.
Another consideration is that timers call their delegated delegate in the ThreadPool thread. Depending on the time and complexity of your logic, you may not want to run it in the thread pool - you may need a dedicated thread. Another factor with timers is that if the processing takes a lot of time, the timer event can be raised again (at the same time) on another thread - which can be a problem if the executed code is not designed or structured for concurrency.
Do not confuse server timers with Windows Timers . Later, they usually refer to WM_TIMER messages that can be delivered to a window, which allows the application to schedule and respond to temporary processing on its main thread without sleep. However, Windows timers can also refer to Win API for low level time (this is not the same as WM_TIMER).
LBushkin May 12 '10 at 20:18 2010-05-12 20:18
source share