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.
Registered users can post here. Sign in or register to post.
  • 1007451581 2018-02-22
  • 8908121580 2018-02-22
  • 141161579 2018-02-22
  • 9421578 2018-02-22
  • 2826901577 2018-02-22
  • 3647361576 2018-02-22
  • 5717551575 2018-02-22
  • 523811574 2018-02-22
  • 6439871573 2018-02-22
  • 8109431572 2018-02-22
  • 8757321571 2018-02-22
  • 5265111570 2018-02-22
  • 3351351569 2018-02-22
  • 5109361568 2018-02-22
  • 4455391567 2018-02-22
  • 9091121566 2018-02-22
  • 24791565 2018-02-22
  • 2486841564 2018-02-21
  • 9847231563 2018-02-21
  • 9264681562 2018-02-21