Forum > Other

unblocked Sleep() for all Platforms

<< < (3/4) > >>

rvk:
Maybe just simply this...


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure Delay(ms: DWORD);var  I: UInt64;begin  I := myGetTick64 + ms;  while I > myGetTick64 do  begin    Application.ProcessMessages;    Sleep(1);  end;end;You can adjust the Sleep(1) to Sleep(10) if you want to.

Josh:
Hi RVK,

do you mean GetTickCount64, or your own custom version  myGetTick64 ...

GetTickCount64 Windows >=Vista, i remember at one time in *nix the counter did not increase when in suspended, this may not be true now though, not on a machine with fpc/laz on it at the moment to test.

rvk:

--- Quote from: Josh on August 27, 2022, 06:18:04 pm ---do you mean GetTickCount64, or your own custom version  myGetTick64 ...
GetTickCount64 Windows >=Vista, i remember at one time in *nix the counter did not increase when in suspended, this may not be true now though, not on a machine with fpc/laz on it at the moment to test.

--- End quote ---
Sorry, yes I mean GetTickCount64.
I have my own custom version of myGetTick64 because I still had Windows XP machines at my customers (although I think they are all replaced now).


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure Delay(ms: DWORD);var  I: UInt64;begin  I := GetTickCount64 + ms;  while I > GetTickCount64 do  begin    Application.ProcessMessages;    Sleep(1);  end;end;
GetTickCount64 should always increase because it's based on the uptime of the machine and it's retrieved every time.
But even if GetTickCount64 doesn't increase during standby/machine suspension it wouldn't be a problem usually because with a Delay(5000) it really wouldn't matter much.

But don't do Delay(24 * 60 * 60 * 1000) for a sleep of 1 day because then, yes, it might not be that accurate.
In that case a different kind of alarm is better.
But my guess is that KodeZwerg is just asking for a Delay of a few seconds while it doesn't lock the OS and your own program.

KodeZwerg:
https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-gettickcount64
This belongs to windows and for windows my code works perfect already but thanks! (since i did not wanted to use RTL blocking Sleep() at all)

I try to play with Josh's code a little, thank you all for answers!!!

rvk:

--- Quote from: KodeZwerg on August 28, 2022, 12:31:30 pm ---https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-gettickcount64
This belongs to windows and for windows my code works perfect already but thanks! (since i did not wanted to use RTL blocking Sleep() at all)

I try to play with Josh's code a little, thank you all for answers!!!

--- End quote ---
The code from Josh also uses sleep.
And without sleep you'll put the cpu at a high percentage.

Btw GetTickCount64 is a Windows function but is recreated in FPC to be cross platform.
Or are you having problems with GetTickCount64 on another platform?

You can try clock_gettime or something else but in that case it isn't really cross platform and you're doing the same thing GetTickCount is doing under the hood.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version