Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SetWaitableTimer

SetWaitableTimer

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Joe OConnor
    wrote on last edited by
    #1

    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; }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups