免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 773 | 回复: 0
打印 上一主题 下一主题

Symbian学习笔记15 之 CPeriodic定时器 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-01-29 12:33 |只看该作者 |倒序浏览

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


您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP