任务调度程序 运行 任务过早几毫秒

Task scheduler run task few milliseconds too early

我有一个带触发器的任务:

At 0:00 every day - after triggered, repeat every 1 hours for a duration of 1 day.

在我的应用程序中,我是这样读取时间的:

dateTimeUtcNow = DateTime.Now;

有时,dateTimeUtcNow 会像 2015-11-11 14:59:59,914

那样显示整点前几毫秒的时间,这种情况很少见

服务器在 Windows Server 2012 R2 上运行,我可以在家庭版上接受它,但不能接受生产版。

为什么?这是一个错误吗?我该如何防止这种情况?

查看 Eric Lippert 关于 DateTime 准确性或准确性的文章。 Link here.

文章中的关键段落:

In short, the question “what time is it?” really should only be answered to a level of precision that reflects the level of accuracy inherent in the system. Most computer clocks are not accurately synchronized to even within a millisecond of official time, and therefore precision beyond that level of accuracy is a lie. It is rather unfortunate, in my opinion, that the DateTime structure does surface as much precision as it does, because it makes it seem like operations on that structure ought to be accurate to that level too. But they almost certainly are not that accurate.

如果您真的需要计时器在午夜之前关闭而不是更早,那么您将不得不强制 "slightly" 未来 date/time 正如评论中已经建议的那样。你真的没有比这更多的控制权了。