Jump to content
xisto Community
Sign in to follow this  
Galahad

Api: Timegettime() timeGetTime() returns negative value

Recommended Posts

Ok, I have this weird problem, using timeGetTime() API. I'm using it in a small application, that shows current system up-time. Now, it has been working fine, but at some point, it started returning negative values, and it counts backwards (decrementing the value)...I don't know if system uptime has anything to do with it; my system has been running for approximately 690 hours, and I first noticed a problem a few days back. Now, I know there is perfectly reasonable explanation for this, but it escapes me. I tried searching for this problem on the web, but had no success. For example, timeGetTime() at some point started returning negative values: -2484000000, and counts down, to -2483999999, -2483999998, etc... Is it just my comp freaking out, or Windows was not designed to run for so long? :) I don't want to restart it, but if that's the only way... :)Oh, btw, I'm using it inside Visual Basic app, but I would hope that has nothing to do with this weird problem :PThanx in advance...

Share this post


Link to post
Share on other sites

This is a flaw in the windows timeGetTime function (not a bug), and is deterministic behaviour.

The windows SDK states:

Note that the value returned by the timeGetTime function is a DWORD value. The return value wraps around to 0 every 2^32 milliseconds, which is about 49.71 days. This can cause problems in code that directly uses the timeGetTime return value in computations, particularly where the value is used to control code execution. You should always use the difference between two timeGetTime return values in computations.

so every ~50 days one of your counters will reset before the other does
and when you take the difference of the two you will get a negitive number.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.