Description
Periodic timer active object.
This class generates regular timer events and handles them with a callback function. The callback is specified as a parameter to Start()
.
The callback may not be called immediately after the signal from the timer request has been generated, for the following reasons:
1. the RunL()
of another active object may be running at the time of the signal
2. other active objects may have a higher priority than the CPeriodic
If timing accuracy is important to your application, you can minimise the first problem by ensuring all RunL()
s complete quickly, and can eliminate the second by giving the CPeriodic a higher priority than any other active object. Although it is generally recommended that timer-related active objects have a high priority, this will not address the problem of CPeriodic timers running behind, because active object scheduling is not pre-emptive.
After a timer signal generated by a CPeriodic, the next signal is requested just before running the callback, and this request can be delayed for the same reasons that running the callback can be delayed. Therefore, a large number N of periods may add up to somewhat more than N times the requested period time. If absolute precision is required in tracking time, do not rely on counting the number of times the callback is called: read the value of the system clock every time you need it.
For many applications, such precision is not required, for example, tick counting is sufficiently accurate for controlling time-outs in a communications program.
Note that you should be familiar with CActive
in order to understand CPeriodic behaviour, but not necessarily with CTimer
.
最关键的: 那个TCallBack函数一定要是static,否则编译器会报错
iPeriodic = CPeriodic::NewL(0); // neutral priority
iPeriodic->Start(KTickInterval,KTickInterval,TCallBack(Tick, this)); // Tick可以为成员方法,一定要是static
TInt CHelloWorldView::Tick(TAny* aObject){ aObject->DoTick(); } // 计时器响应
if(iPeriodic->IsActive())
{
iPeriodic->Cancel(); //取消
}