Timers

The .NET BCL contains 3 timers:

  1. System.Timers.Timer – This is a timer in the sense of a stopwatch, meaning it tells you how long each operation took. It has methods for pausing and resuming. However, it can also work like a standard System.Windows.Forms.Timer; you just need to set the property System.Timers.Timer.AutoReset to true. When the interval elapses, the event is raised Elapsed.
  2. System.Threading.Timer – What sets it apart from the others is the ability to change the period while it is running. You learn that the interval has elapsed through the delegate TimerCallback, which has to be specified in the constructor.
  3. System.Windows.Forms.Timer – A classic timer that raises an event after the specified interval elapses. It also lets you pause the thread by setting the property System.Windows.Forms.Timer.Enabled to false, or assign your own object to the timer through the property Tag .

So it is up to you to decide which Timer best suits your needs. And if you still cannot choose, cut your own diamond or search the internet.

Categories

Leave a Reply