定时器DispatcherTimer比较 [英] Comparing Timer with DispatcherTimer

查看:142
本文介绍了定时器DispatcherTimer比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么区别 System.Windows.Forms.Timer()之间 System.Windows.Threading.DispatcherTimer()?在这种情况下,我们应该使用它们?任何最佳做法?

what is a difference between System.Windows.Forms.Timer() and System.Windows.Threading.DispatcherTimer() ? In which cases, we should use them? any best practices ?

推荐答案

Windows.Forms.Timer 使用Windows窗体消息循环来处理计时器事件。应该编写在Windows窗体应用程序中使用时序事件时使用,并且你希望计时器火主UI线程上。

Windows.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 是WPF计时机制。您正在使用WPF和 - 它应该当你要处理类似的方式正被使用(每个线程都有自己的调度员虽然这并不局限于单个线程)。它激发同一个线程分派的事件。

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.

在一般情况下, WPF == DispatcherTimer Windows窗体== Forms.Timer

话虽这么说,也有<一个href=\"http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx\"><$c$c>System.Threading.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.

这篇关于定时器DispatcherTimer比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆