Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use Windows.Forms.Timer at all?

Tags:

c#

winforms

timer

I read this excellent article Comparing the Timer Classes in the .NET Framework Class Library and came to the conclusion that anything I could do with Windows.Forms.Timer I can do better with Timers.Timer - and then some.

So the obvious question that comes to mind is: Why is the Windows.Forms Timer offered at all?

Legacy (backward compatibility) support?

Other?

like image 471
ih8ie8 Avatar asked Oct 19 '12 15:10

ih8ie8


2 Answers

The main convenience of the Windows.Forms.Timer is that its events are fired on the UI (Winforms) thread. If your timer events perform UI operations, it may be the simplest alternative (instead of calling Control.Invoke/BeginInvoke or SynchronizationContext.Post/Send inside all of your events).

like image 125
Ohad Schneider Avatar answered Oct 02 '22 16:10

Ohad Schneider


The Windows.Forms.Timer events get invoked on the UI thread so you can update the UI from the event handlers directly, which is not normally the case with Timers.Timer (as you would get cross thread access violation exceptions).

And, as @Robert Harvey answered, it also has designer support.

like image 34
Oded Avatar answered Oct 02 '22 16:10

Oded