标签:boost 定时器
VC定时执行任务flyfish 2015-1-19
SetTimer
使用timeSetEvent
头文件支持
#include <MMSystem.h> #pragma comment(lib, "winmm.lib")
static void CALLBACK Function(UINT wTimerID,UINT nMsg,DWORD dwUser,DWORD dw1,DWORD dw2);
void ClassName::Function(UINT wTimerID,UINT nMsg,DWORD dwUser,DWORD dw1,DWORD dw2) { ClassName* pDlg=(ClassName*)dwUser; }
int nTimeID=timeSetEvent(100,100,Function,(DWORD)this,TIME_PERIODIC);
释放定时器资源
timeKillEvent(nTimeID);
MMRESULT timeSetEvent( UINT uDelay, UINT uResolution, LPTIMECALLBACK lpTimeProc, DWORD_PTR dwUser, UINT fuEvent );
头文件支持 #include <boost/asio.hpp> #include <boost/bind.hpp> #include <boost/date_time/posix_time/posix_time.hpp> 类中的函数声明 void BoostOnTimer(const boost::system::error_code& /*e*/, boost::asio::deadline_timer* t,UINT nElapse); void BoostSetTimer(UINT nElapse ); 类中的函数实现 void ClassName::BoostOnTimer(const boost::system::error_code& /*e*/, boost::asio::deadline_timer* t,UINT nElapse) { //任务执行 //终止条件 t->expires_at(t->expires_at() + boost::posix_time::milliseconds(nElapse)); t->async_wait(boost::bind(&ClassName::BoostOnTimer,this,boost::asio::placeholders::error, t,nElapse)); } void ClassName::BoostSetTimer(UINT nElapse )//毫秒 { boost::asio::io_service io; boost::asio::deadline_timer t(io, boost::posix_time::milliseconds(nElapse)); t.async_wait(boost::bind(&ClassName::BoostOnTimer,this,boost::asio::placeholders::error, &t, nElapse)); io.run(); } 调用方式 BoostSetTimer(3000);
标签:boost 定时器
原文地址:http://blog.csdn.net/flyfish1986/article/details/42873297