.NET 中计时器的最大精度是多少? [英] What is the maximum precision of the Timer in .NET?

查看:25
本文介绍了.NET 中计时器的最大精度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 System.Timers 中 Timer 类的精度是多少,因为它是双精度(这似乎表明您可以有几分之一毫秒).它是什么?

I'm wondering what the precision of the Timer class is in System.Timers, because it's a double (which would seem to indicate that you can have fractions of milliseconds). What is it?

推荐答案

Windows 桌面操作系统在大约 40 毫秒以下确实不准确.操作系统根本不是实时的,因此会出现明显的非确定性抖动.这意味着虽然它可能会报告小至毫秒或更小的值,但您不能真正指望这些值真正有意义.因此,即使将 Timer 间隔设置为某个亚毫秒值,您也不能依靠设置和触发之间的时间来真正达到您所说的那样.

Windows desktop OSes really aren't accurate below about 40ms. The OS simply isn't real time and therefore presents significant non-deterministic jitter. What that means is that while it may report values down to the millisecond or even smaller, you can't really count on those values to be really meaningful. So even if the Timer interval gets set to some sub-millisecond value, you can't rely on times between setting and firing to actually be what you said you wanted.

此外,您正在运行的整个框架是不确定的(GC 可能会暂停您并在 Timer 应该触发的时候进行收集),并且您最终会承受大量的风险试图做任何时间紧迫的事情.

Add to this fact that the entire framework you're running under is non-deterministic (the GC could suspend you and do collection duing the time when the Timer should fire) and you end up with loads and loads of risk trying to do anything that is time critical.

这篇关于.NET 中计时器的最大精度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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