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. Simple question - Threads and Timers

Simple question - Threads and Timers

Scheduled Pinned Locked Moved C / C++ / MFC
questiondesignjson
7 Posts 5 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.
  • N Offline
    N Offline
    no_reg_name
    wrote on last edited by
    #1

    I have a worker thread and need to start and stop a timer. As I understand there are two ways to do this, using CWnd class and handling OnTimer()or SetTimer(hWnd, ....) API call, but both rely on having a UI to receive WM_TIMER messages. Is this correct? :confused: If yes what is the best way to implement a timer in a worker thread, that does not interact with the UI at all?

    T B PJ ArendsP B 4 Replies Last reply
    0
    • N no_reg_name

      I have a worker thread and need to start and stop a timer. As I understand there are two ways to do this, using CWnd class and handling OnTimer()or SetTimer(hWnd, ....) API call, but both rely on having a UI to receive WM_TIMER messages. Is this correct? :confused: If yes what is the best way to implement a timer in a worker thread, that does not interact with the UI at all?

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #2

      no_reg_name wrote: sing CWnd class and handling OnTimer()or SetTimer(hWnd, ....) API call, but both rely on having a UI to receive WM_TIMER messages. Is this correct? Very Much Correct ,No problem using timer in UI no_reg_name wrote: what is the best way to implement a timer in a worker thread, that does not interact with the UI at all? You have to use Sleep api to simulate the Timer in worker thread.


      "I Think this Will Help"

      visit me at http://www.thisisalok.tk
      1 Reply Last reply
      0
      • N no_reg_name

        I have a worker thread and need to start and stop a timer. As I understand there are two ways to do this, using CWnd class and handling OnTimer()or SetTimer(hWnd, ....) API call, but both rely on having a UI to receive WM_TIMER messages. Is this correct? :confused: If yes what is the best way to implement a timer in a worker thread, that does not interact with the UI at all?

        B Offline
        B Offline
        Blake Miller
        wrote on last edited by
        #3

        Look at CreateWaitableTimer and use WaitForSingleObject or else WaitForMultipleObjects, if you have another event or such to signal your thread to exit or to perform some other work. Instead of using Sleep() os LeepEx() which will lock up your thread until the sleep has timed out.

        1 Reply Last reply
        0
        • N no_reg_name

          I have a worker thread and need to start and stop a timer. As I understand there are two ways to do this, using CWnd class and handling OnTimer()or SetTimer(hWnd, ....) API call, but both rely on having a UI to receive WM_TIMER messages. Is this correct? :confused: If yes what is the best way to implement a timer in a worker thread, that does not interact with the UI at all?

          PJ ArendsP Offline
          PJ ArendsP Offline
          PJ Arends
          wrote on last edited by
          #4

          There are two ways to use the SetTimer API. The first is as you said where you specify an HWND that will recieve the WM_TIMER message. The second is to use the CALLBACK function that you specify in the fourth parameter of the SetTimer() function. See SetTimer[^] and TimerProc[^] in MSDN for more info.


          "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

          Within you lies the power for good; Use it!

          B 1 Reply Last reply
          0
          • N no_reg_name

            I have a worker thread and need to start and stop a timer. As I understand there are two ways to do this, using CWnd class and handling OnTimer()or SetTimer(hWnd, ....) API call, but both rely on having a UI to receive WM_TIMER messages. Is this correct? :confused: If yes what is the best way to implement a timer in a worker thread, that does not interact with the UI at all?

            B Offline
            B Offline
            basementman
            wrote on last edited by
            #5

            You do not have to have a window to create a timer. You can create a timer if you supply NULL for the hWnd and supply a callback proc.  onwards and upwards...

            1 Reply Last reply
            0
            • PJ ArendsP PJ Arends

              There are two ways to use the SetTimer API. The first is as you said where you specify an HWND that will recieve the WM_TIMER message. The second is to use the CALLBACK function that you specify in the fourth parameter of the SetTimer() function. See SetTimer[^] and TimerProc[^] in MSDN for more info.


              "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

              B Offline
              B Offline
              basementman
              wrote on last edited by
              #6

              I guess you can type faster than me....:laugh: Beat me by two seconds...  onwards and upwards...

              PJ ArendsP 1 Reply Last reply
              0
              • B basementman

                I guess you can type faster than me....:laugh: Beat me by two seconds...  onwards and upwards...

                PJ ArendsP Offline
                PJ ArendsP Offline
                PJ Arends
                wrote on last edited by
                #7

                basementman wrote: I guess you can type faster than me Yeah, my two fingers do move pretty fast:~


                "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

                Within you lies the power for good; Use it!

                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