Poco库Timer定时器
来源:互联网 发布:安卓与php服务器端 编辑:程序博客网 时间:2024/06/07 00:08
Poco库是一个很强大的C++库,其中常使用到的定时器类为Timer,下面就编写一个简单的定时器程序,具体说明参见注释’//’部分:
#include <stdio.h>#include <iostream>#include <string>#include "Poco\Timer.h"using namespace std;using Poco::Timer; // 使用Timer基类的成员using Poco::TimerCallback; // 使用TimerCallback基类的成员class StatTimer{public: Timer timer; TimerCallback<StatTimer> callback; // 套用模板,将StatTimer类关联起来 bool end; StatTimer(); bool start(); void onTimer(Timer& t); void stop();};StatTimer::StatTimer() : timer(0, 2000), callback(*this, &StatTimer::onTimer), end(false){}// timer(0, 2000),第一个参数默认设置为0,2000代表时间间隔为2秒// callback的第二个参数指定定时器需要做的具体事情bool StatTimer::start(){ try { timer.start(callback); // 启动定时器线程 //started = true; } catch (...) { return false; end = true; } return true;}void StatTimer::onTimer(Timer&/*t*/){ static size_t counter = 0; ++counter; printf("\r%uA", counter); if (counter > 5) end = true;}void StatTimer::stop(){ timer.stop(); // 终止定时器线程}int main(){ cout << "Hello World!" << endl << endl; StatTimer *timer = new StatTimer(); if (!timer->start()) { cout << "Failed to start timer" << endl;; } while (1) { if (timer->end) { timer->stop(); break; } } cout << endl; system("pause"); return 0;}
阅读全文
1 0
- Poco库Timer定时器
- Poco::Timer
- Timer 定时器
- TIMER 定时器
- timer 定时器
- timer 定时器
- timer定时器
- 定时器 Timer
- 定时器Timer
- timer定时器
- Timer 定时器
- Timer定时器
- 定时器TIMER
- 定时器Timer
- timer定时器
- Timer 定时器
- Timer定时器
- 定时器 timer
- 阿里面试回来,想和Java程序员谈一谈
- Android bitmap讲解与实践
- 初学Web:计算机气质个人主页
- 开发一个自动点击工具
- R语言使用Apriori规则完成关联挖掘
- Poco库Timer定时器
- ARIMA差分自回归模型python代码
- EffectiveC++学习笔记-条款3
- 【每天一点linux】进程间通信--信号
- Ubuntu16.04 安装 Adouble Falsh Player
- 学习kotlin第13天_具体化的类型参数、内联属性、解构声明、集合
- 在Android Studio 和 Eclipse 的 git 插件操作 "代码提交"以及"代码冲突"
- python实现多线程post方法进行压测脚本模板
- Java基础教程23-static举例