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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Timer

Timer

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
6 Posts 6 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.
  • C Offline
    C Offline
    Castello07
    wrote on last edited by
    #1

    Hi to all... I want to create a timer in visual c++ (without using the class CWnd)that periodically send a message (for example a string). How is the best solution? I thought....create a thread that stay in sleep and after this time sleep send the message... I'll wait for any suggetion.. thanks!!

    L R S M T 5 Replies Last reply
    0
    • C Castello07

      Hi to all... I want to create a timer in visual c++ (without using the class CWnd)that periodically send a message (for example a string). How is the best solution? I thought....create a thread that stay in sleep and after this time sleep send the message... I'll wait for any suggetion.. thanks!!

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      see the API CreateTimerQueueTimer

      "What classes are you using ? You shouldn't call stuff if you have no idea what it does"
      Christian Graus in the C# forum

      led mike

      1 Reply Last reply
      0
      • C Castello07

        Hi to all... I want to create a timer in visual c++ (without using the class CWnd)that periodically send a message (for example a string). How is the best solution? I thought....create a thread that stay in sleep and after this time sleep send the message... I'll wait for any suggetion.. thanks!!

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

        My suggestion is to use a waitable timer. You create a waitable timer with a call to ::CreateWaitableTimer()[^]. Wait for the timer to be signalled with ::WaitForSingleObject() or similar. If you're using a secondary thread you may want to stop the timer and exit the thread. I suggest you signal an event for that, created with ::CreateEvent(). Unless you're familiar with multithreading I suggest you read Joe Newcomer's article[^] on the subject to avoid the most common pitfalls, such as avoiding ::sleep() as the plague and never call GUI related stuff from a worker thread. Hope this helps -- Roger


        _It's supposed to be hard, otherwise anybody could do it!

        Regarding CodeProject: "resistance is pointless; you will be assimilated"_

        1 Reply Last reply
        0
        • C Castello07

          Hi to all... I want to create a timer in visual c++ (without using the class CWnd)that periodically send a message (for example a string). How is the best solution? I thought....create a thread that stay in sleep and after this time sleep send the message... I'll wait for any suggetion.. thanks!!

          S Offline
          S Offline
          SimonSays
          wrote on last edited by
          #4

          You could always try timeSetEvent to create a multimedia timer -- I have used that from time to time. That essentially creates the new thread for you and calls a function you specify when it times out. Saves you some of the details about thread management.

          1 Reply Last reply
          0
          • C Castello07

            Hi to all... I want to create a timer in visual c++ (without using the class CWnd)that periodically send a message (for example a string). How is the best solution? I thought....create a thread that stay in sleep and after this time sleep send the message... I'll wait for any suggetion.. thanks!!

            M Offline
            M Offline
            MaxVampire82
            wrote on last edited by
            #5

            1. U can use the api : SetTimer() / KillTimer() 2. U can use the multimedia timer : timeSetEvent() / timeKillEvent() Chinese coder.

            1 Reply Last reply
            0
            • C Castello07

              Hi to all... I want to create a timer in visual c++ (without using the class CWnd)that periodically send a message (for example a string). How is the best solution? I thought....create a thread that stay in sleep and after this time sleep send the message... I'll wait for any suggetion.. thanks!!

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

              Castello07 wrote:

              I thought....create a thread that stay in sleep and after this time sleep send the message...

              I Believe that will be right way, as this will not interrupt your main thread when you call sleep function!

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta VC Forum Q&A :- I/ IV

              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