开发者

Timers in a .NET application

I would like to know what kind of timers can be used in a C# application and what are their implications in term of cuncurrency in a multi-threaded environment.

Could you explain me or link me to an e开发者_运维知识库saustive tutorial?

Thank you.


There are two forms of timers - ones that are message based, and typically UI centric, and ones that are thread-based.

The UI versions are the Timer class from Windows Forms or the DispatcherTimer in WPF. These tend to report timings (normally) on the UI thread, and basically use the standard message pump to handle timing.

The System.Timers.Timer and System.Threading.Timer classes use a separate thread for handling timers. These work very well, but the "Tick" events happen on a separate thread. This means you need to handle thread synchronization or UI threading synchronization if you use these.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜