有时我需要休眠非整数毫秒,但找不到这样做的方法。 例如,如果我想休眠半毫秒,我想这样做:
Thread.Sleep(0.5);
但不能,因为 Sleep 只支持整数。
最佳答案
如果你的时间安排如此重要,而不是你使用了完全错误的工具来完成工作,因为
Thread.Sleep(n) means blocking the current thread for at least the number of timeslices (or thread quantums) that can occur within n milliseconds. The length of a timeslice is different on different versions/types of Windows and different processors and generally ranges from 15 to 30 milliseconds. This means the thread is almost guaranteed to block for more or than n milliseconds on different computers. The likelihood that your thread will re-awaken exactly after n milliseconds is about as impossible as impossible can be. So, Thread.Sleep is pointless for timing.
您可以阅读所有相关信息 here .
注意:如果您发布您尝试解决的问题
Thread.Sleep
我们或许可以为您指明正确的方向
关于c# - 如何获得与 Thread.Sleep 支持 double 值类似的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17887583/