Time controlled execution of algorithm

Hello dear all,

I need some advice with delaying my execution.
There is a piece of algorithm that i want to run only once in every 500ms.
Thereby i used "GetTickCount()" to get the ticks after running my algorithm..
now that is a short piece of algorithm and completes very fast

So i thought i would add a "delay()" or "sleep()" after running algorithm for the remainder of time within 500ms.

Then i can check the difference of ticks, if they be more than 500, i will proceed to execute my algorithm once again.

My question is:
1. Which is the best approach to this delay causing, a while loop, a Sleep(), a delay()...? Kindly suggest.
2. How best do i get precise delays.?

Thanks
Running your algorithm, then waiting for 500ms isn't the same thing as running your algorithm every 500ms. You'll need a timer for that.
Topic archived. No new replies allowed.