Thread.Sleep(1)会发生什么

如果没改变SystemTimer的resolution,那么会睡眠15.625ms(64HZ)。
但很多程序会通过NtSetTimerResolution等接口申请改变timer的resolution。比如QQ,会将其设置1ms。
那么此时会睡眠1~2ms之间的值。

Say the ActualResolution is set to 156,250, the interrupt heartbeat of the system will run at 15.625 ms periods or 64 Hz and a call to Sleep is made with a desired delay of 1 ms. Two scenarios are to be looked at:

  • The call was made < 1ms (ΔT) ahead of the next interrupt. The next interrupt will not confirm that the desired period of time has expired. Only the following interrupt will cause the call to return. The resulting sleep delay will be ΔT + 15.625ms.
  • The call was made >= 1ms (ΔT) ahead of the next interrupt. The next interrupt will force the call to return. The resulting sleep delay will be ΔT.

http://www.windowstimestamp.com/description

posted @ 2022-09-08 22:08  dewxin  阅读(230)  评论(0编辑  收藏  举报