I have used QueryPerformanceCounter & QueryPerformanceFrequency to detect System uptime, and it seemed to have worked, -well, until this morning that is.
Now, I am getting an uptime of 1 hour 20minutes and change, even though system has been up for over three days (Both systemInfo and "net statistics workstation" correctly identify that system has been up for three days plus). Nothing of significance really happened an hour and 20 minutes ago. (I have been logged in for the last three hours !).
I recall that PerformanceCounter may be off by a few clicks on multi-core/processor machines, but this is a an error of about 80 hours. Can someone tell me why the following code doesn't work ?
function GetPerformanceCounterTick: Int64;
var PCount: Int64;
if QueryPerformanceCounter(PCount) then Result := PCount
else raise exception.create('QueryPerformanceCounter Error');
function GetTimerFrequency: Int64;
var Frequency: Int64;
if QueryPerformanceFrequency(Frequency) then Result := Frequency
else raise exception.create('QueryPerformanceFrequency Error');
var f, t : int64;
r, d, h, m, s : word;
f := GetTimerFrequency;
t := GetPerformanceCounterTick;
r := t div f; // in seconds
s := r mod 60; r := r div 60;
m := r mod 60; r := r div 60;
h := r mod 60; r := r div 24;
d := r;
if d >0 then result := Format('%3d Days %2d Hours %2d Minutes %2d Seconds', [d, h, m, s])
else if h > 0 then result := Format('%2d Hours %2d Minutes %2d Seconds', [h, m, s])
else if m > 0 then result := Format('%2d Minutes %2d Seconds', [m, s])
else result := Format('%2d Seconds', [s])