1 int main(const std::vector<std::string>& args) 2 { 3 Timer timer; 4 Timestamp time; 5 TimerTask::Ptr pTask = new TimerTaskAdapter<LovemuApp>(*this,&LovemuApp::onTimer); 6 timer.schedule(pTask,500,500);//每2.5s执行一次timer动作 7 _event.wait(); 8 // if((time.elapsed() >= 1790000)&&(pTask->lastExecution().elapsed() < 130000)) 9 pTask->cancel(); 10 if(pTask->isCancelled()) 11 std::cout<<"定时任务已停止"<<std::endl; 12 return Application::EXIT_OK; 13 } 14 void onTimer(TimerTask& task) 15 { 16 /*TO DO*/ 17 Poco::Thread::sleep(100); 18 std::cout<<"hello"<<std::endl; 19 // task.cancel(); 20 _event.set(); 21 }
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)