为什么 .NET 中有 5 个版本的计时器类? [英] Why there are 5 Versions of Timer Classes in .NET?
本文介绍了为什么 .NET 中有 5 个版本的计时器类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么.Net框架中有五个定时器类,分别是:
Why are there five timer classes in the .Net framework, namely the following:
System.Timers.Timer
System.Threading.Timer
System.Windows.Forms.Timer
System.Web.UI.Timer
System.Windows.Threading.DispatcherTimer
为什么 Timer 类有多个版本?它们之间有什么区别?
Why are there several versions of the Timer class? And what are the differences between them?
推荐答案
这里是对主要计时器的描述以及我认为最值得注意的点.
Here's a description of the primary timers and the points that i find to be the most noteworthy.
Winforms.Timer
- UI 线程上的标记不能保证在特定时间进行标记
- 滴答延迟直到 UI 线程空闲
- 如果 UI 线程繁忙,将跳过滴答声
DispatcherTimer
- 在 UI 线程上调用
- 可以为生成滴答声所需的空闲"级别设置优先级
- 将跳过刻度
Threading.Timer
- 在线程池中的工作线程上打勾 - 没有用于指定线程的选项
- ticks 总是准时触发
- 没有一个被跳过——你必须在处理之前的滴答时防范新的滴答声
- 未处理的异常会使应用程序崩溃
Timers.Timer
- 环绕线程计时器
- 从 CLR 线程池中获取的工作线程上的滴答声
- 可以通过提供 SynchronizationObject 强制在特定线程上打勾
- ticks 总是准时触发
- 没有被跳过
- 默默地吃掉异常
这篇关于为什么 .NET 中有 5 个版本的计时器类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文