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. TimerAPCProc() Not Being Called With SetWaitableTimer()

TimerAPCProc() Not Being Called With SetWaitableTimer()

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 2 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.
  • H Offline
    H Offline
    Hummer2097
    wrote on last edited by
    #1

    I wrote the below code in an attempt to set a 500ms timer. CreateWaitableTimer returns a valid handle and SetWaitableTimer() returns 1 indicating success, however TimerAPCProc() never gets called. Can anybody see what's wrong with this code? VOID CALLBACK __stdcall TimerAPCProc(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue, DWORD dwTimerHighValue) { } void SetTimer() { m_hTimer = CreateWaitableTimer(NULL, false, NULL); LARGE_INTEGER liInterval; liInterval.QuadPart = -500000000; int dSuccess = SetWaitableTimer(m_hTimer, &liInterval, 0, TimerAPCProc, NULL, false); } Thanks for any help you can offer.

    M 1 Reply Last reply
    0
    • H Hummer2097

      I wrote the below code in an attempt to set a 500ms timer. CreateWaitableTimer returns a valid handle and SetWaitableTimer() returns 1 indicating success, however TimerAPCProc() never gets called. Can anybody see what's wrong with this code? VOID CALLBACK __stdcall TimerAPCProc(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue, DWORD dwTimerHighValue) { } void SetTimer() { m_hTimer = CreateWaitableTimer(NULL, false, NULL); LARGE_INTEGER liInterval; liInterval.QuadPart = -500000000; int dSuccess = SetWaitableTimer(m_hTimer, &liInterval, 0, TimerAPCProc, NULL, false); } Thanks for any help you can offer.

      M Offline
      M Offline
      Mauro Leggieri
      wrote on last edited by
      #2

      Is the thread that creates the timer exiting too fast? Also read http://msdn.microsoft.com/en-us/library/ms681951(VS.85).aspx[^] to know when APC callbacks are called.

      H 1 Reply Last reply
      0
      • M Mauro Leggieri

        Is the thread that creates the timer exiting too fast? Also read http://msdn.microsoft.com/en-us/library/ms681951(VS.85).aspx[^] to know when APC callbacks are called.

        H Offline
        H Offline
        Hummer2097
        wrote on last edited by
        #3

        Thanks for the reply and information. The timer is being created in the main thread so it's definitely not a problem of it exiting too soon. I also tried setting the time to -1 just to try and get it to call the TimerAPCProc but still it wouldn't. I solved the problem by switching to SetTimer(). For some reason I thought SetTimer() worked in seconds rather than milliseconds and that's the only reason I was using SetWaitableTimer(). I was looking for an alternative time and noticed SetTimer() took a value in milliseconds so it was fine for what I needed. I still don't understand why SetWaitableTimer() wouldn't work but it doesn't really matter now.

        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