#include "stdafx.h" #include<windows.h> #include<stdio.h> int count=0; HANDLE hEvent,tq,timer1,timer2; void __stdcall f1(PVOID,BOOL){ printf("計(jì)時(shí)器1: 1s %d\n",++count); if(count>20)SetEvent(hEvent); } void __stdcall f2(PVOID,BOOL){ printf("計(jì)時(shí)器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("開始計(jì)時(shí)\n"); WaitForSingleObject(hEvent,INFINITE); DeleteTimerQueueTimer(tq,timer1,INVALID_HANDLE_VALUE); DeleteTimerQueueTimer(tq,timer2,INVALID_HANDLE_VALUE); DeleteTimerQueueEx(tq,INVALID_HANDLE_VALUE); return 0; }
|