Different timers in .net

  • 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值