负值表示相对时间,正值表示绝对时间,定时器精度为100ns (1ns=1/10亿 s),所以 -50000000 代表5秒,详见MSDN。

程序一为自动重置(先等待5秒,然后每1秒输出一次):

#include "stdafx.h"
#include<Windows.h>
#include<iostream>
#include<time.h> using namespace std;
int main(){
LARGE_INTEGER li;
li.QuadPart = -; HANDLE hTimer = CreateWaitableTimer( NULL,FALSE,NULL );
if( !SetWaitableTimer( hTimer,&li,,NULL,NULL, )) {
cout<<"error"<<endl;
CloseHandle( hTimer );
return ;
}
while ( ){
clock_t c_beg = clock();
WaitForSingleObject(hTimer,INFINITE);
clock_t end = clock() - c_beg;
cout<<"time:"<<end<<endl;
}
CloseHandle(hTimer);
system("pause");
return ;
}

程序二为手动重置(每秒输出),其实当CreateWaitableTimer第二个参数为TRUE时(即手动重置),SetWaitableTimer的第三个参数是不起作用的:

#include "stdafx.h"
#include<Windows.h>
#include<iostream>
#include<time.h> using namespace std;
int main(){
LARGE_INTEGER li;
li.QuadPart = -; HANDLE hTimer = CreateWaitableTimer( NULL,TRUE,NULL );
if( !SetWaitableTimer( hTimer,&li,,NULL,NULL, )) {
cout<<"error"<<endl;
CloseHandle( hTimer );
return ;
}
while ( ){
clock_t c_beg = clock();
WaitForSingleObject(hTimer,INFINITE);
SetWaitableTimer( hTimer,&li,,NULL,NULL, );
clock_t end = clock() - c_beg;
cout<<"time:"<<end<<endl;
}
CloseHandle(hTimer);
system("pause");
return ;
}

程序三:APC(异步调用过程)加入定时器

见MSDN http://msdn.microsoft.com/en-us/library/windows/desktop/ms686898%28v=vs.85%29.aspx

最新文章

  1. CYQ.Data V5 从入门到放弃ORM系列:教程 - MAction类使用
  2. 动画的使用&mdash;Drawable Animation
  3. 基于socket的客户端和服务端聊天简单使用 附Demo
  4. Yii2中request的使用
  5. java环境基础步骤 svn
  6. Solr资料
  7. BizTalk开发系列(三十七) 性能监视器在BizTalk性能测试中的使用
  8. 51nod 1027大数乘法
  9. 数据库操作(C#)
  10. C语言下动态库相互调用
  11. Hibernate入门(2)- 不用配置用注解
  12. UVa297 Quadtrees
  13. Android TabActivity与Activity之间的动画跳转(主要Tabhost中跳转出来的动画效果解决)
  14. Entity Framework with MySQL 学习笔记一(拦截)
  15. [Swust OJ 322]--东6宿舍灵异事件(中缀表达式转化为后缀表达式的简单运用)
  16. springCloud项目练习
  17. Linux下的 &gt;, &gt;&gt;, &lt;, ps, |, grep, /dev/null
  18. jQuery基础操作
  19. 使用 Gradle 构建 Java 项目
  20. MyBatis 的动态 SQL 使用说明

热门文章

  1. jq点击切换按钮最简洁代码
  2. httpClient的post方法使用form格式数据调用接口
  3. NodeJS入门学习
  4. jenkins自动发送邮件配置
  5. 是因为Session只能让服务器在一次连续的会话中记住你,而Cookie是记住浏览器一段时间
  6. spring学习-3
  7. Redis的一些常用命令操作
  8. tp中自定义跳转页面
  9. 类和对象(9)—— new和delete
  10. Raid信息丢失数据恢复及oracle数据库恢复验证方案