#include "stdafx.h"
#include<windows.h>
#include<stdio.h>
int count=0;
HANDLE hEvent,tq,timer1,timer2;
void __stdcall f1(PVOID,BOOL){
printf("计时器1: 1s %d\n",++count);
if(count>20)SetEvent(hEvent);
}
void __stdcall f2(PVOID,BOOL){
printf("计时器2: 2.5s %d\n",++count);
if(count>20)SetEvent(hEvent);
}
int _tmain(int argc, _TCHAR* argv[])
{
if(NULL==(hEvent=CreateEvent(NULL,FALSE,FALSE,"myevent"))){
printf("CreateEvent失败:%d\n",GetLastError());
return 1;
}
ResetEvent(hEvent);
if(NULL==(tq=CreateTimerQueue())){
printf("CreateTimerQueue失败:%d\n",GetLastError());
return 1;
}
if(!(CreateTimerQueueTimer(&timer1,tq,(WAITORTIMERCALLBACK)f1,0,1000,1000,0)
&&CreateTimerQueueTimer(&timer2,tq,(WAITORTIMERCALLBACK)f2,0,2500,2500,0))){
printf("CreateTimerQueueTimer失败:%d\n",GetLastError());
return 1;
}
printf("开始计时\n");
WaitForSingleObject(hEvent,INFINITE);
DeleteTimerQueueTimer(tq,timer1,INVALID_HANDLE_VALUE);
DeleteTimerQueueTimer(tq,timer2,INVALID_HANDLE_VALUE);
DeleteTimerQueueEx(tq,INVALID_HANDLE_VALUE);
return 0;
}
|