System.Windows.Forms.Timer vs. System.Threading.Timer vs. System.Timers.Timer



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

Using the System.Windows.Forms.Timer is a relatively obvious choice for user interface programming.  Choosing between the other two options is less obvious and generally the choice between the two is insignificant.  If hosting within an IContainer is necessary then obviously System.Timers.Timer is the right choice.  However, if no specific System.Timers.Timer feature is required, then I suggest choosing System.Threading.Timer by default, simply because it is a slightly lighter weight implementation.

0 comments:

Listen to nirmaln - sakara - playlist audio songs at MusicMazaa.com