是Environment.TickCount受系统时间调整? [英] Is Environment.TickCount affected by system time adjustments?

查看:850
本文介绍了是Environment.TickCount受系统时间调整?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,在.NET BCL财产Environment.TickCount是如何实现的。特别是我想现在如果是受系统时间调整的。

I'm curious as to how the .NET BCL property Environment.TickCount is implemented. In particular I'd like to now if it is affected by system time adjustments.

我的第一个猜测,该属性是如何实现的是,这只是一个围绕的 GetTickCount的方法。然而,对于的GetTickCount 方法状态它的受影响的GetSystemTimeAdjustment功能的做了调整,但是的 Environment.TickCount 没有提及关于时间调整的事情。

My first guess as to how the property was implemented was that it was simply a managed wrapper around the GetTickCount method. However, the documentation for the GetTickCount method states that it is affected by adjustments made by the GetSystemTimeAdjustment function but the documentation for Environment.TickCount does not mention anything about time adjustments.

我试图找出是否Environment.TickCount可以作为一个(虽然低precision)持续增加的时间值。

I'm trying to figure out if the Environment.TickCount can be used as a (albeit low-precision) consistently increasing time value.

推荐答案

没有,的 Environment.TickCount 不受系统时间调整。这是文档的我的内部pretation,但我的好奇心要求难以证明,所以我有以下code运行时调整系统来回1小时:

No, Environment.TickCount is not affected by adjustments of the system time. That was my interpretation of the documentation, but my curiosity demanded harder proof, so I had the following code run while adjusting the system back and forth one hour:

while (true)
{
    Console.WriteLine(Environment.TickCount);
    Thread.Sleep(1000); 
}

...和输出表明并不受时间调整一个完美的序列

...and the output showed a perfect sequence that was not affected by the time adjustments.

更新
所以我做了一些更多的功课,由Marcus'在下面的意见问题引发的。我敢肯定(不能证实虽然)这Environment.TickCount会调用的 的GetTickCount 具有以下在该文档中提到的:

Update
So I did some more homework, triggered by Marcus' question in the comments below. I am quite sure (could not confirm though) that Environment.TickCount makes a call to GetTickCount that has the following mentioned in the docs:

在的GetTickCount的分辨率   功能被限制为第   系统定时器,这是   通常,在10的范围内   毫秒至16毫秒。该   该GetTickCount的分辨率   功能也受   由作出调整   GetSystemTimeAdjustment功能。

The resolution of the GetTickCount function is limited to the resolution of the system timer, which is typically in the range of 10 milliseconds to 16 milliseconds. The resolution of the GetTickCount function is also affected by adjustments made by the GetSystemTimeAdjustment function.

因此​​,虽然它不影响通过改变系统时间,似乎的的受了由调用的 SetSystemTimeAdjustment

So, while it is not affected by altering the system time, it seems that will be affected by adjustments that are caused by a call to SetSystemTimeAdjustment.

这篇关于是Environment.TickCount受系统时间调整?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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