I wanted to call function every 5 minutes
I tried
AutoFunction(){
cout << "Auto Notice" << endl;
Sleep(60000*5);
}
while(1){
if(current->tm_hour == StartHour && current->tm_min == StartMinut && current->tm_sec == StartSec){
CallStart();
}
AutoFunction();
Sleep(1000);
}
I want refresh the while every 1 second and at the same time call AutoFunction(); every 5 minutes, but without waiting the Sleep in AutoFunction
because I have to refresh the while(1) every 1 sec to check time to start another function
I thought to do it like
while(1){
if(current->tm_hour == StartHour && current->tm_min == StartMinut && current->tm_sec == StartSec){
CallStart();
}
Sleep(1000);
}
while(1){
AutoFunction();
Sleep(60000*5);
}
but I don’t think so both will working together
Thank You
For those of us who are unfamiliar with threads and Boost libraries, this can be done with a single while loop:
in this code,
curTimeis a function I made up that returns the Unix Timestamp as an int. Substitute in whatever is appropriate from your time library of choice.