TCHAR szError[255]; HANDLE hTimer; __int64 qwDueTime; LARGE_INTEGER liDueTime; /* ResvTimer */ if ( hTimer = CreateWaitableTimer(NULL, FALSE,"recvtimeTimer" ) ) { // Create an integer that will be used to signal the timer // 2 seconds from now. qwDueTime = (-2) * _SECOND; // Copy the relative time into a LARGE_INTEGER. liDueTime.LowPart = (DWORD) ( qwDueTime & 0xFFFFFFFF ); liDueTime.HighPart = (LONG) ( qwDueTime >> 32 ); if (SetWaitableTimer(hTimer,&liDueTime,60000,RecvTimerProc,NULL,FALSE)) { TRACE("Called the RecvTimerProc to set local time ./n"); while (RunFlag) { SleepEx(INFINITE,/* Wait forever*/TRUE /* Put thread in an alertable state*/); } } else { wsprintf( szError, "SetWaitableTimer failed with Error %d.", GetLastError() ); MessageBox( NULL, szError, "Error", MB_ICONEXCLAMATION ); } CloseHandle( hTimer ); // END of timer }
一个定时器模型
最新推荐文章于 2020-12-19 16:39:29 发布