定时器DispatcherTimer比较

编程入门 行业动态 更新时间:2024-10-10 05:23:18
本文介绍了定时器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 的

话虽这么说,也有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比较

本文发布于:2023-06-03 09:51:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/471219.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定时器   DispatcherTimer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!