Chinaunix首页 | 论坛 | 博客
  • 博客访问: 22195
  • 博文数量: 28
  • 博客积分: 670
  • 博客等级: 上士
  • 技术积分: 285
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-09 11:27
文章分类

全部博文(28)

文章存档

2011年(28)

我的朋友
最近访客

分类: 嵌入式

2011-01-29 12:33:47

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(); //取消
}


阅读(335) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~