Yaron 53 Posted April 18, 2021 (edited) I use a thread to update an animated 'please wait' dialog while doing other things in the background. The issue is, I want to be able to dismiss the please wait dialog instantly and since I use animations, I use "Sleep" commands to to time the animation and take minimum CPU time. However, for some reason, doing Sleep(10) returns a vastly different result than calling For I := 0 to 1 do If Terminated = False then Sleep(5); which for some reasons takes ~30ms to complete. For reference, calling For I := 0 to 9 do If Terminated = False then Sleep(1); takes ~150ms. My problem is with Delphi 7, but I doubt it's specific to this version of Delphi, any ideas? Edited April 18, 2021 by Yaron Share this post Link to post
Yaron 53 Posted April 18, 2021 Nevermind, I replaced Sleep with WaitForSingleObject and used an event to break out of the wait when closing the dialog. Share this post Link to post
FPiette 383 Posted April 18, 2021 You should not access the UI from a thread. Share this post Link to post
David Heffernan 2345 Posted April 19, 2021 14 hours ago, Yaron said: any ideas? Answer can be found in the documentation of Sleep. Sleep can only wait for multiples of system ticks. And your system appears to tick at a frequency of 15ms. Which is typical, that being the default tick frequency. There are many many discussions of this online. Here's one: https://stackoverflow.com/questions/3744032/why-are-net-timers-limited-to-15-ms-resolution 2 Share this post Link to post
Remy Lebeau 1394 Posted April 19, 2021 And also: https://stackoverflow.com/questions/9518106/winapi-sleep-function-call-sleeps-for-longer-than-expected 1 Share this post Link to post