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 esaustive tutorial?
Thank you.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.