简体   繁体   English

Thread.Sleep在Windows 8下无法与Silverlight 5一起使用

[英]Thread.Sleep Not Working with Silverlight 5 under Windows 8

Background: There is a development for vehicle dynamics, as an attempt to add realistic behavior, calculation results are performed real time with 1:1 scale to real life, ie, 1 seconds in real life = 1 second in computing results. 背景技术:车辆动力学的发展是一种尝试,它增加了真实的行为,计算结果以1:1的比例实时执行到现实生活中,即现实生活中为1秒=计算结果中为1秒。

Problem: Under Windows XP/Vista/7 and even MacOS, everything is working as expected, however in Windows 8 the application runs (what seems to be) exactly 2x times slower. 问题:在Windows XP / Vista / 7甚至MacOS下,一切都按预期运行,但是在Windows 8中,应用程序运行(似乎是)速度慢了2倍。

Details: Delays are performed by 详细信息:延迟由执行

System.Threading.Thread.Sleep((Int32)time_delta)

Being time_delta, calculated as needed to match 1:1 time ratio. 为time_delta,根据需要进行计算以匹配1:1的时间比率。

Under Windows 8, what it takes 1 second in real life is taking 2 seconds, I could however use time_delta/2.0f however seems like a dirty trick. 在Windows 8下,现实生活中需要1秒的时间是2秒,但是我可以使用time_delta / 2.0f,但这似乎是一个肮脏的把戏。

Question: Is there a proper way to fix that? 问题:是否有解决此问题的正确方法?

References: I searched and found that seems to be reported issues: Missing .NET features in Metro style application? 参考文献:我搜索并发现似乎是报告的问题: Metro风格应用程序中缺少.NET功能?

This link says http://msdn.microsoft.com/en-us/library/d00bd51t.aspx that Thread.Sleep is supported under Windows 8. 该链接表示http://msdn.microsoft.com/en-us/library/d00bd51t.aspx Windows 8支持Thread.Sleep。

Thanks in advance. 提前致谢。


Update: I was wrong, the Windows 8 delays are not exactly 2 times slower, the resolution for Sleep() seems to have changed dramatically and (at least under my test) is very variable, so I ended up using real-time adjusting each time I detected an offset, a bit CPU intensive but is working now. 更新:我错了,Windows 8的延迟并不慢2倍,Sleep()的分辨率似乎发生了巨大变化,并且(至少在我的测试中)变化很大,所以我最终使用了实时调整每个我检测到偏移时,CPU占用了一点时间,但现在可以正常工作。

您是否尝试使用TimeSpan(例如TimeSpan.FromSeconds(time_delta))代替Int32?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM