CreateTimerQueueTimer学习笔记 .
2014-04-04 12:44
495 查看
定时器队列(Timer Queue)可以使用CreateTimerQueue函数创建。定时器队列中的定时器是轻量级对象,可以在一定时间间隔之后调用指定的回调函数(可以只调用一次,也可以是周期性的)。这种等待操作由线程池中某个线程处理的(系统级别)。
向定时器队列中添加定时器可以使用CreateTimerQueueTimer函数。更新一个计时器队列中的计时器可以使用 ChangeTimerQueueTimer 函数。这两个函数中你可以指定一个回调函数,如果设定时间到达,线程池中某个线程会调用该回调函数。
使用 DeleteTimerQueueTimer函数可以取消挂起的计时器。当不再使计时器队列的时候,调用 DeleteTimerQueueEx 函数删除计时器队列,该函数调用是会取消并删除任何在该队列中等待的计时器。
向定时器队列中添加定时器可以使用CreateTimerQueueTimer函数。更新一个计时器队列中的计时器可以使用 ChangeTimerQueueTimer 函数。这两个函数中你可以指定一个回调函数,如果设定时间到达,线程池中某个线程会调用该回调函数。
使用 DeleteTimerQueueTimer函数可以取消挂起的计时器。当不再使计时器队列的时候,调用 DeleteTimerQueueEx 函数删除计时器队列,该函数调用是会取消并删除任何在该队列中等待的计时器。
#include <iostream> #include <windows.h> #include <stdio.h> #include <tchar.h> using namespace std; //事件对象 HANDLE g_Event = NULL; static int COUNT = 0; VOID CALLBACK TimerRoutine( PVOID lpParameter, BOOLEAN TimerOrWaitFired ) { if(NULL == lpParameter) { OutputDebugString(_T("lpParameter is null。。")); return; } printf("the values of param is :%d\n",*(int*)lpParameter); COUNT++; /*if(COUNT >= 3) { SetEvent(g_Event); }*/ } int main(int argc,TCHAR *argv[]) { HANDLE hTimer= NULL; HANDLE hTimerQueue = NULL; int arg = 123; g_Event = CreateEvent(NULL,TRUE,FALSE,NULL); if(NULL == g_Event) { OutputDebugString(_T("CreateEvent失败。。")); return 1; } hTimerQueue = CreateTimerQueue(); if(NULL == hTimerQueue) { OutputDebugString(_T("CreateTimerQueue失败。。")); return 1; } if(!CreateTimerQueueTimer(&hTimer,hTimerQueue,WAITORTIMERCALLBACK(TimerRoutine),&arg,5000,1000,NULL)) { OutputDebugString(_T("CreateTimerQueueTimer失败。。")); return 1; } if(WaitForSingleObject(g_Event,INFINITE) !=WAIT_OBJECT_0) { OutputDebugString(_T("WaitForSingleObject失败。。")); } CloseHandle(g_Event); if(!DeleteTimerQueue(hTimerQueue)) { OutputDebugString(_T("DeleteTimerQueue失败。。")); } return 0; }
相关文章推荐
- CreateTimerQueueTimer学习
- Priority_Queue 优先队列 C++学习笔记
- C++ STL学习笔记7--priority_queue优先队列
- STL学习笔记— —特殊容器queue
- libev 学习笔记之timer实现原理
- MFC的CreateTimerQueueTimer和timeSetEvent两个高精度定时器的比较
- java.util.queue学习笔记
- C++学习笔记(字符串string、vector_deque、queue,multiset、map、multimap、容器拷贝问题)
- iOS学习笔记-114.多线程13——NSOperationQueue和NSInvocationOperation合用实现多线程
- Java中Timer的学习笔记(一)
- C++学习笔记(字符串string、vector_deque、queue,multiset、map、multimap、容器拷贝问题)(复制粘贴,方便后面翻阅)
- iOS学习笔记-118.多线程17——NSOperationQueue队列的取消、暂停、恢复
- Linux 驱动学习笔记2 -- Timer
- python 学习笔记 - Queue & Pipes,进程间通讯
- 步步为营 SharePoint 开发学习笔记系列 七、SharePoint Timer Job 开发
- JAVA学习笔记43——其他容器简介1:Queue+Deque+Enumeration
- ArrayBlockingQueue学习笔记
- CreateTimerQueueTimer在DllMain中调用导致的loader lock
- STL学习笔记-- queue
- 步步为营 SharePoint 开发学习笔记系列 七、SharePoint Timer Job 开发