为什么要完全使用Windows.Forms.Timer? [英] Why use Windows.Forms.Timer at all?
问题描述
我阅读了这篇出色的文章比较.NET Framework类中的计时器类库并得出结论,我可以使用 Windows.Forms.Timer
做任何事情,而使用 Timers.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.
因此想到的一个显而易见的问题是:为什么根本没有提供 Windows.Forms
计时器?
So the obvious question that comes to mind is: Why is the Windows.Forms
Timer offered at all?
支持旧版(向后兼容)吗?
Legacy (backward compatibility) support?
其他?
推荐答案
Windows.Forms.Timer
的主要便利是,其事件在UI(Winforms)线程上触发.如果您的计时器事件执行UI操作,则它可能是最简单的选择(而不是在所有事件中调用 Control.Invoke/BeginInvoke
或 SynchronizationContext.Post/Send
).
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).
这篇关于为什么要完全使用Windows.Forms.Timer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!