Why are there 5 versions of timer classes in .NET?

Why there are five classes of timers in the .Net Framework, namely:

  1. System.Timers.Timer
  2. System.Threading.Timer
  3. System.Windows.Forms.Timer
  4. System.Web.UI.Timer
  5. System.Windows.Threading.DispatcherTimer

Why are there several versions of the Timer class? And how do they differ?

+66
c # timer
Apr 25 2018-12-12T00:
source share
3 answers

Here you go:

Comparing timer classes in the .NET Framework class library https://web.archive.org/web/20150329101415/https://msdn.microsoft.com/en-us/magazine/cc164015.aspx

Content

  • System.Windows.Forms.Timer
  • System.Timers.Timer
  • System.Threading.Timer
  • Timer programming with timers
  • Work with the event register with a timer
  • Conclusion
+20
Apr 25 2018-12-12T00:
source share

Timers.Timer generates an event after a specified interval with the ability to generate recurring events. MSDN

Windows.Forms.Timer is a control for winforms.

Web.UI.Timer performs asynchronous or synchronous Web.UI.Timer web page at a specific interval. MSDN

Threading.Timer - timer for callbacks. Creates a new theme for work. Served by thread pool threads. MSDN

So, these timers have different goals, and they are served by different tools.

+11
Mar 28 '18 at 16:27
source share

Here is a description of the main timers and items that I find most noteworthy.

Winforms.Timer

  • check marks in the user interface stream do not guarantee a ticket at a specific time
  • ticks are delayed until the user interface thread is free
  • will skip ticks if the UI thread is busy

DispatcherTimer

  • invoked in a user interface thread
  • you can set a priority for what level of "idle" is required to generate a tick
  • will skip checkmarks

Threading.Timer

  • marks a worker thread from a thread pool - there is no way to specify a thread
  • ticks always shoot on time
  • none of them are skipped - you should beware of new ticks while still processing the old tick

Timers.Timer

  • Wrap around the stream timer
  • marks on a workflow taken from the CLR thread pool
  • can force a tick on a specific thread by providing a SynchronizationObject
  • ticks always shoot on time
  • none of them are missed
  • silently eats exceptions
+4
Aug 30 '19 at 18:00
source share



All Articles