Reputation: 9377
Why are there five timer classes in the .Net framework, namely the following:
System.Timers.Timer
System.Threading.Timer
System.Windows.Forms.Timer
System.Web.UI.Timer
System.Windows.Threading.DispatcherTimer
Why are there several versions of the Timer class? And what are the differences between them?
Upvotes: 113
Views: 36589
Reputation: 5234
Here's a description of the primary timers and the points that i find to be the most noteworthy.
Winforms.Timer
DispatcherTimer
Threading.Timer
Timers.Timer
Upvotes: 53
Reputation: 5803
This question is now answered by Microsoft in the MSDN article for system.timers.timer
https://learn.microsoft.com/en-us/dotnet/api/system.timers.timer?view=net-5.0
Tip
Be aware that .NET includes four classes named Timer, each of which offers different functionality:
System.Timers.Timer
(this topic): fires an event at regular intervals. The class is intended for use as a server-based or service component in a multithreaded environment; it has no user interface and is not visible at runtime.
System.Threading.Timer
: executes a single callback method on a thread pool thread at regular intervals. The callback method is defined when the timer is instantiated and cannot be changed. Like the System.Timers.Timer class, this class is intended for use as a server-based or service component in a multithreaded environment; it has no user interface and is not visible at runtime.
System.Windows.Forms.Timer
(.NET Framework only): a Windows Forms component that fires an event at regular intervals. The component has no user interface and is designed for use in a single-threaded environment.
System.Web.UI.Timer
(.NET Framework only): an ASP.NET component that performs asynchronous or synchronous web page postbacks at a regular interval.
Upvotes: 4
Reputation: 1691
Timers.Timer
generates an event after a set interval, with an option to generate recurring events. MSDN
Windows.Forms.Timer
is a Control for winforms.
Web.UI.Timer
performs asynchronous or synchronous Web page postbacks at a defined interval. MSDN
Threading.Timer
is the timer for Callbacks. Creates a new Thread for working. Served by thread pool threads. MSDN
So, these timers have different purposes, also they are served by different tools.
Upvotes: 12