• Multi-threads timers: System.Threading.Timer and System.Timers.Timer (.net framework):

App will handle timer event on a thread pool thread. Timers.Timer is a wrapper for Threading.Timer. They are used for doing time-consuming tasks. 

If a System.Timers.Timer is used in a WPF application, it is worth noting that the System.Timers.Timer runs on a different thread then the user interface (UI) thread.

In order to access objects on the user interface (UI) thread, it is necessary to post the operation onto the Dispatcher of the user interface (UI) thread using Invoke or Begi

nInvoke.

Reasons for using a DispatcherTimer opposed to a System.Timers.Timer are that theDispatcherTimer runs on the same thread as the Dispatcher and a DispatcherPrio

rity can be set on the DispatcherTimer.

  • Single-thread timers: System.Windows.Forms.Timer(Windows Forms Timer)and System.Windows.Threading.DispatcherTimer(WPF timer)
Based on Windows message loop, app will handle timer event synchronously, so they may block UI.They are called in the same thread as the application. They are

 used for small tasks such as updating UI.

posted on 2014-01-07 11:52  chuwachen  阅读(139)  评论(0编辑  收藏  举报