SetWaitableTimer
-
In my current project I have to run a procedure at a specific time during the night. For this I am using the "SetWaitableTimer" function (see code below). This code runs perfectly on a Win2K machine. But on a Win98 machine, it looses 3 Seconds per minute. ie. If I start it at 12 Midday to run at 12 Midnight (12 Hours difference) then the scheduler will run 36 Minutes late. Any help at all would be usefull. Joe. [Code] HANDLE hScheduleTimer; bool CCashierLogon::StartScheduler() { ... hScheduleTimer = CreateWaitableTimer(NULL, FALSE, NULL); if (hScheduleTimer != NULL) { SYSTEMTIME sysSch; //24/Apr/2001 00:00:00 sysSch.wYear = 2001; sysSch.wMonth = 4; sysSch.wDay = 24; sysSch.wDayOfWeek = 0; //Ignore sysSch.wHour = 0; sysSch.wMinute = 0; sysSch.wSecond = 0; sysSch.wMilliseconds = 0; //Ignore FILETIME ftSch, ftUTC; LARGE_INTEGER liSch; SystemTimeToFileTime(&sysSch, &ftSch); LocalFileTimeToFileTime(&ftSch, &ftUTC); liSch.LowPart = ftUTC.dwLowDateTime; liSch.HighPart = ftUTC.dwHighDateTime; long lPeriod = (1000 * 60 * 60 * 24); //Every 24 Hours if (SetWaitableTimer(hScheduleTimer, &liSch, lPeriod, NULL, NULL, FALSE) == TRUE) { CWinThread *pSchThread; pSchThread = AfxBeginThread(MainScheduler, //Function Name (PVOID)hScheduleTimer, //Handle THREAD_PRIORITY_NORMAL, //Normal 0, //Stack Size CREATE_SUSPENDED); //Create Suspended pSchThread->m_bAutoDelete = FALSE; pSchThread->ResumeThread(); } } ... } UINT MainScheduler(LPVOID pParam) { HANDLE hSchedule; hSchedule = (HANDLE)pParam; while(1) { if (WaitForSingleObject(hSchedule, INFINITE) == WAIT_OBJECT_0) { // //Do Our Midnight Processing Here... // } } return 0; }