what is a difference between System.Windows.Forms.Timer()
and System.Windows.Threading.DispatcherTimer()
? In which cases, we should use them? any best practices ?
views:
1922answers:
2Windows.Forms.Timer uses the windows forms message loop to process timer events. It should be used when writing timing events that are being used in Windows Forms applications, and you want the timer to fire on the main UI thread.
DispatcherTimer is the WPF timing mechanism. It should be used when you want to handle timing in a similar manner (although this isn't limited to a single thread - each thread has its own dispatcher) and you're using WPF. It fires the event on the same thread as the Dispatcher.
In general, WPF==DispatcherTimer and Windows Forms==Forms.Timer.
That being said, there is also System.Threading.Timer, which is a timer class that fires on a separate thread. This is good for purely numerical timing, where you're not trying to update the UI, etc.
simple example in WPF on Digital Clock http://madhukaudantha.blogspot.com/2010/04/digital-clock-in-wpf.html