Environment.TickCount是否受系统时间调整影响?
我很好奇.NET BCL 属性Environment.TickCount 是如何实现的。我现在特别想知道它是否受到 的影响系统时间调整。
我对该属性如何实现的第一个猜测是它只是一个围绕 GetTickCount 方法。但是, GetTickCount 方法的文档指出它受到 GetSystemTimeAdjustment 函数所做调整的影响,但 Environment.TickCount 没有提及任何有关时间调整的内容。
我试图弄清楚是否可以将 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.
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.
I'm trying to figure out if the Environment.TickCount can be used as a (albeit low-precision) consistently increasing time value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
否,
Environment.TickCount
不受系统时间调整的影响。这是我对文档的解释,但我的好奇心需要更严格的证明,因此我运行了以下代码,同时来回调整系统一小时:...输出显示了一个完美的序列,不受时间调整的影响。
更新
因此,我做了一些更多的作业,由下面评论中马库斯的问题引发。我非常确定(但无法确认)Environment.TickCount 会调用
GetTickCount
在文档中提到了以下内容:因此,虽然它不受更改系统时间的影响,但似乎将受到调用
SetSystemTimeAdjustment
。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:...and the output showed a perfect sequence that was not affected by the time adjustments.
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: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
.不会,它不受系统时间调整的影响。
是否适合“持续增加的时间价值”取决于您的具体要求。来自 MSDN 文档:
No, it's not affected by system time adjustments.
Whether it's suitable for a "consistently increasing time value" depends on your exact requirements. From the MSDN documentation: