是什么区别 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 的
话虽这么说,也有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比较
发布评论