Poco::util::timertask Poco Timer Implementation

Source: Internet
Author: User
#include <iostream>
#include <stdio.h>
#include <Poco / Util / TimerTask.h>
#include <Poco / Util / Timer.h>
#include <Poco / Task.h>
#include <Poco / Timestamp.h>
using namespace std;

/ * Poco Timer Test * /
class TestTimer: public Poco :: Util :: TimerTask
{
public:
void run ();
};

void TestTimer :: run ()
{
cout << "Test Timer" << endl;
}
int main ()
{
TestTimer obj;
Poco :: Util :: Timer * timer_;
timer_ = new Poco :: Util :: Timer ();
/ *
2 cyclic tasks:
1. When creating a timer, the first execution time is when it is created
2.The first execution time is the time specified by the second parameter
Ranch
timer _-> scheduleAtFixedRate (& obj, 0, 1000);
* /

/ * Get the current time * /
Poco :: Timestamp timeobj;
//timeobj.epochMicroseconds ();
//cout<<timeobj.epochMicroseconds()<<endl;
// epochMicroseconds returns the subtle number of UTC current time
// timeobj = timeobj.epochMicroseconds () + 3000000;
// timer _-> scheduleAtFixedRate (& obj, timeobj, 1000); // The first execution delay after the timer is created is three seconds

/ * Execute the timer once and give the specified time, if the time has elapsed, execute immediately
Ranch
Ranch
// timer _-> schedule (& obj, timeobj.epochMicroseconds ()-2000000);
timer _-> schedule (& obj, 5000,5000); // The timer starts after five seconds and starts every five seconds
getchar ();
return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.