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. Can I start a timer inside a thread [modified]

Can I start a timer inside a thread [modified]

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

    I want to do a periodic checking of data inside a thread. Can i start Timer in a UI thread derived from CWinThread? -- modified at 1:50 Friday 27th April, 2007

    A R 2 Replies Last reply
    0
    • B BlrBoy

      I want to do a periodic checking of data inside a thread. Can i start Timer in a UI thread derived from CWinThread? -- modified at 1:50 Friday 27th April, 2007

      A Offline
      A Offline
      Arman S
      wrote on last edited by
      #2

      "Timer" - what exactly you mean? If you mean CWnd::SetTimer/KillTimer pair, than you can do it only if there is a window in your UI thread and meantime it is logical to assign the timer to it. Do you have windows? Or only is message pump there?

      -- ===== Arman

      1 Reply Last reply
      0
      • B BlrBoy

        I want to do a periodic checking of data inside a thread. Can i start Timer in a UI thread derived from CWinThread? -- modified at 1:50 Friday 27th April, 2007

        R Offline
        R Offline
        Roger Stoltz
        wrote on last edited by
        #3

        The short answer is "yes, you can". ;) From Arman's reply I guess you didn't think about a UI-thread and a CWinThread derived object from the start and you don't really need a UI-thread. I suggest you create an ordinary worker thread, see here[^] how to do it and avoid common pitfalls. Create a waitable timer with ::CreateWaitableTimer( NULL, FALSE, NULL )[^] inside your worker thread and wait on the timer handle with e.g. ::WaitForMultipleObjects(...). Start the timer with ::SetWaitableTimer(...)[^] and make it periodic.


        "It's supposed to be hard, otherwise anybody could do it!" - selfquote
        "High speed never compensates for wrong direction!" - unknown

        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