I'm trying to write a loop that runs once every x milliseconds, is there a way to do something like this effectively in c++?
Hope someone could help me with an example how I would go about writing a loop like this
I'm trying to write a loop that runs once every x milliseconds, is there a way to do something like this effectively in c++?
Hope someone could help me with an example how I would go about writing a loop like this
One and the simplest approach would be using windows.h library's Sleep() function.
#include "windows.h"
...
while(1)
{
for(...) {} // your loop
Sleep(miliseconds);
if(something) { break; } // to prevent infinite looping.
}
...
A better solution would be using std::this_thread::sleep_for() from < thread > header. more documentation and examples here.