I am trying to use a function (the doAction() function in the example below) after a specific amount of time passes. In the following example, I have to use the function 10 times, first being 1 millisecond after having entered the 'while loop', second being 3 seconds after having entered the 'while loop', and so on.
Simply put, I need a method to measure how much time passed from the beginning of the 'while loop' to any given moment so that I can apply the doAction() function at specific desired moments.
QUESTION: What method can I use to track how much time has passed between an initial moment and any other moment afterwards? Edited: I am using windows 7
Currently I am using the following setup with the GetSystemTime() function which is working, though has some issues:
int countVar = 0;
int timeList[10] = {1, 3, 6, 7, 9, 11, 14, 15, 17, 19};
/*values representing milliseconds after initiating the while loop*/
SYSTEMTIME timeBuffer;
GetSystemTime(&timeBuffer);
int initialTime = timeBuffer.wMilliseconds + (timeBuffer.wSecond*1000) + (timeBuffer.wMinute*60000);
int currentTime;
while (true)
{
GetSystemTime(&timeBuffer);
currentTime = timeBuffer.wMilliseconds + (timeBuffer.wSecond*1000) + (timeBuffer.wMinute*60000) - initialTime;
if (currentTime >= timeList(countVar)
{
doAction();
if (countVar!=9)
countVar++;
else
break;
}
}
the doAction function is just a really fast function which wouldn't have a significant impact on the time.
void doAction() /*this is the action done which is completed in
microseconds hence would not have a significant
delay in time*/
{
....
}
The problems this setup has however is as follows:
1) if the system time was 59 minutes and 59 seconds, the next system time I would look for would be over 59 minutes and 59 seconds, which I would not be able to obtain unless I also included wHours into the calculation, and the same can be said for days and weeks, etc.
2) I would prefer to use a function that when used, starts counting down milliseconds, and when reusing that function would tell me how many milliseconds have been used since the countdown started. However I haven't found any function like this available in msdn as of yet.
If anyone could point me to the direction of a better function to use than GetSystemTime() to measure how much time passes after a certain moment, that would be awesome!
Edited: I am using Windows 7