c# - 如何获得与 Thread.Sleep 支持 double 值类似的结果?

标签 c# multithreading double sleep milliseconds

有时我需要休眠非整数毫秒,但找不到这样做的方法。 例如,如果我想休眠半毫秒,我想这样做:

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/

相关文章:

c# - 以编程方式在 Hierarchy Unity 中导入 Assets

c# - c#中的memcpy函数

c# - Windows 窗体组合框 - 数据绑定(bind)到多个属性

python - 将 stdout 和 stderr 从辅助线程重定向到 PyQt4 QTextEdit

所有 Double 的 grails 值转换器

c# - 如何正确从 appsettings.json 中提取 NLog DB ConnectionString

php - 在非线程环境中使用线程安全扩展 (APC) 有什么危害吗? (PHP)

java - 中断异常 e

c# - 将 double 转换为 int,它是四舍五入还是只是去掉数字?

qt - QML 中的 Double 现在完全等于 Real 吗?