Poco::Timer 定时器demo

timer.cc

#include <cstdlib>
#include <iostream>

#include <Poco/Timer.h>
#include <Poco/Thread.h>

using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;

class TimerExample
{
   public:
      void onTimer(Timer& timer)
      {
         std::cout << "onTimer called." << std::endl;
      }
};


// ===  FUNCTION  ======================================================================
//         Name:  main
//  Description:  main function
// =====================================================================================
   int
main ( int argc, char *argv[] )
{
   long totalTime        = 2000,
        startInterval    = 0,
        periodicInterval = 0;

   if (argc == 3) {
      startInterval    = atol(argv[1]);
      periodicInterval = atol(argv[2]);
   }

   TimerExample te;
   Timer timer(startInterval, periodicInterval);
   timer.start(TimerCallback<TimerExample>(te, &TimerExample::onTimer));

   Thread::sleep(totalTime);
   return EXIT_SUCCESS;
}     // ----------  end of function main  ----------

编译:

[root@slayer poco]# g++ timer.cc -lPocoFoundation

结果:

[root@slayer poco]# ./a.out
onTimer called.
[root@slayer poco]# ./a.out 1000 600
onTimer called.
onTimer called.
[root@slayer poco]# ./a.out 1500 100
onTimer called.
onTimer called.
onTimer called.
onTimer called.
onTimer called.
onTimer called.

 

转载于:https://www.cnblogs.com/Leo-Forest/archive/2013/02/18/2915282.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值