Boost中timer的简易用法

时间:2023-03-08 23:31:00
Boost中timer的简易用法

  boost::asio::deadline_timer timer_;  

     timer_(io_service),  

      timer_.expires_from_now(boost::posix_time::seconds(1));
timer_.async_wait(
boost::bind(&sender::handle_timeout, this,
boost::asio::placeholders::error)); void handle_timeout(const boost::system::error_code& error)
{
if (!error)
{
timer_.expires_from_now(boost::posix_time::seconds(1));
timer_.async_wait(
boost::bind(&sender::handle_timeout, this,
boost::asio::placeholders::error));
/*Insert Your Functions*/ }
}

在你所用的类中声明一个boost 的timer 见第一句话,

初始化这个timer 第二句话,

第三句,第四句话,使timer正常的工作起来。

后面的的timer的时间到后,的执行程序。

执行程序中,进行了迭代,可以再次计时,