Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;每5分钟调用一次函数_C++_While Loop - Fatal编程技术网

C++ c++;每5分钟调用一次函数

C++ c++;每5分钟调用一次函数,c++,while-loop,C++,While Loop,我想每5分钟调用一次函数 我试过了 但我不认为两人会一起工作 感谢您对于我们这些不熟悉线程和Boost库的人,这可以通过一个while循环完成: void AutoFunction(){ cout << "Auto Notice" << endl; } //desired number of seconds between calls to AutoFunction int time_between_AutoFunction_calls = 5*60; int

我想每5分钟调用一次函数
我试过了

但我不认为两人会一起工作


感谢您

对于我们这些不熟悉线程和Boost库的人,这可以通过一个while循环完成:

void AutoFunction(){
    cout << "Auto Notice" << endl;
}

//desired number of seconds between calls to AutoFunction
int time_between_AutoFunction_calls = 5*60;

int time_of_last_AutoFunction_call = curTime() - time_between_AutoFunction_calls;

while(1){
    if (should_call_CallStart){
        CallStart();
    }

    //has enough time elapsed that we should call AutoFunction?
    if (curTime() - time_of_last_AutoFunction_call >= time_between_AutoFunction_calls){
        time_of_last_AutoFunction_call = curTime();
        AutoFunction();
    }
    Sleep(1000);
}
void AutoFunction(){

听起来是使用线程的好时机。线程a永远循环,调用
AutoFunction
并休眠五分钟。同时,线程B永远循环,在适当的时候调用
CallStart
并休眠一秒钟。看起来像是一个完美的使用案例,适用于一个计时器。[1]:
while(1){

    if(current->tm_hour == StartHour && current->tm_min == StartMinut && current->tm_sec == StartSec){
        CallStart();
    }

    Sleep(1000);
}
while(1){

    AutoFunction();
    Sleep(60000*5);
}
void AutoFunction(){
    cout << "Auto Notice" << endl;
}

//desired number of seconds between calls to AutoFunction
int time_between_AutoFunction_calls = 5*60;

int time_of_last_AutoFunction_call = curTime() - time_between_AutoFunction_calls;

while(1){
    if (should_call_CallStart){
        CallStart();
    }

    //has enough time elapsed that we should call AutoFunction?
    if (curTime() - time_of_last_AutoFunction_call >= time_between_AutoFunction_calls){
        time_of_last_AutoFunction_call = curTime();
        AutoFunction();
    }
    Sleep(1000);
}