what is a difference between System.Windows.Forms.Timer() and System.Windows.Threading.DispatcherTimer() ? In which cases, we should use them? any best practices ?
what is a difference between System.Windows.Forms.Timer() and System.Windows.Threading.DispatcherTimer() ? In which cases, we should
Share
Windows.Forms.Timeruses 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.DispatcherTimeris 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 == DispatcherTimerandWindows Forms == Forms.Timer.That being said, there is also
System.Threading.Timer, which is a timerclassthat fires on a separate thread. This is good for purely numerical timing, where you’re not trying to update the UI, etc.