0

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, i.e., 1 seconds in real life = 1 second in computing results.

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.

Details: Delays are performed by

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

Being time_delta, calculated as needed to match 1:1 time ratio.

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.

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?

This link says http://msdn.microsoft.com/en-us/library/d00bd51t.aspx that Thread.Sleep is supported under Windows 8.

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.

Community
  • 1
  • 1
RandomGuy42
  • 301
  • 4
  • 14
  • dCan you verify that `Sleep(1000)` actually takes 2,000 ms? Or is your program doing some smaller sleeps? `Sleep(7)`, for example, could very well take 15 ms because the resolution of `Sleep` might not be at the millisecond level. – Jim Mischel Apr 23 '13 at 20:04
  • @JimMischel Small Sleeps here and there as needed, that seems to be the problem, I am thinking about getting all delays on a single one, looking first if the GUI does not get out of sync as it is being updated in real-time. Will Update after testing. – RandomGuy42 Apr 23 '13 at 22:22

1 Answers1

0

Did you try to use a TimeSpan (e.g. TimeSpan.FromSeconds(time_delta)) instead of an Int32?

Boluc Papuccuoglu
  • 2,318
  • 1
  • 14
  • 24