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. Timers in VC++

Timers in VC++

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
9 Posts 7 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
    nripun
    wrote on last edited by
    #1

    Is it mandatory to use KillTimer() if a SetTimer is used? For example, i use SetTimer(ID1,100,NULL). After 100milliseconds the timer expires and it is handled in the OnTimer() function. Now if i have to start a timer again with the same ID do i have to use KillTimer(ID1)?

    E N S T 4 Replies Last reply
    0
    • N nripun

      Is it mandatory to use KillTimer() if a SetTimer is used? For example, i use SetTimer(ID1,100,NULL). After 100milliseconds the timer expires and it is handled in the OnTimer() function. Now if i have to start a timer again with the same ID do i have to use KillTimer(ID1)?

      E Offline
      E Offline
      Eytukan
      wrote on last edited by
      #2

      It wont get expired untill you "kill" it. It keeps ticking. Now if i have to start a timer again with the same ID do i have to use KillTimer(ID1)? It'll overwrite the existing timer. For example, if you had set the interval as 2000, now the new SetTimer with the same ID but the interval set as 1000, it will start ticking everysecond (1000).


      --[V]--

      [My Current Status]

      1 Reply Last reply
      0
      • N nripun

        Is it mandatory to use KillTimer() if a SetTimer is used? For example, i use SetTimer(ID1,100,NULL). After 100milliseconds the timer expires and it is handled in the OnTimer() function. Now if i have to start a timer again with the same ID do i have to use KillTimer(ID1)?

        S Offline
        S Offline
        shilianghui2
        wrote on last edited by
        #3

        you don't have to use killtimer function to kill the timer.The statement for that function in the msdn shows that if you use an id that is existed,the old timer will be replaced.

        L 1 Reply Last reply
        0
        • N nripun

          Is it mandatory to use KillTimer() if a SetTimer is used? For example, i use SetTimer(ID1,100,NULL). After 100milliseconds the timer expires and it is handled in the OnTimer() function. Now if i have to start a timer again with the same ID do i have to use KillTimer(ID1)?

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #4

          From the docs for ::SetTimer. Holds true for CWnd::SetTimer too...

          If the hWnd parameter is not NULL and the
          window specified by hWnd already has a timer with the value
          nIDEvent, then the existing timer is replaced by the new timer.
          When SetTimer replaces a timer, the timer is reset. Therefore, a
          message will be sent after the current time-out value elapses, but the
          previously set time-out value is ignored.


          Nibu thomas Software Developer Faqs by Michael dunn

          1 Reply Last reply
          0
          • S shilianghui2

            you don't have to use killtimer function to kill the timer.The statement for that function in the msdn shows that if you use an id that is existed,the old timer will be replaced.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            It is still good practice to kill the old one though. The tigress is here :-D

            D 1 Reply Last reply
            0
            • L Lost User

              It is still good practice to kill the old one though. The tigress is here :-D

              D Offline
              D Offline
              Dennis Gourjii
              wrote on last edited by
              #6

              Sure thing it is good practice, how else would you make the system free the resources allocated for this timer? Chances are that when you replace the timer the whole thing deallocates correctly in the SetTimer API. Still better to be absolutely sure and kill the timer by hand. The name of the function (KillTimer) sounds terrifying, but it's safe to use unlike other functions with frightening names (e.g. TerminateThread). :)

              N 1 Reply Last reply
              0
              • D Dennis Gourjii

                Sure thing it is good practice, how else would you make the system free the resources allocated for this timer? Chances are that when you replace the timer the whole thing deallocates correctly in the SetTimer API. Still better to be absolutely sure and kill the timer by hand. The name of the function (KillTimer) sounds terrifying, but it's safe to use unlike other functions with frightening names (e.g. TerminateThread). :)

                N Offline
                N Offline
                Nibu babu thomas
                wrote on last edited by
                #7

                HAND wrote:

                (e.g. TerminateThread). :)

                :shudderrrrrrr: :eek::( It's the UnderTaker...Run


                Nibu thomas Software Developer Faqs by Michael dunn

                T 1 Reply Last reply
                0
                • N Nibu babu thomas

                  HAND wrote:

                  (e.g. TerminateThread). :)

                  :shudderrrrrrr: :eek::( It's the UnderTaker...Run


                  Nibu thomas Software Developer Faqs by Michael dunn

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

                  Nibu thomas wrote:

                  t's the UnderTaker...Run

                  What about Great Khali :)

                  "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
                  • N nripun

                    Is it mandatory to use KillTimer() if a SetTimer is used? For example, i use SetTimer(ID1,100,NULL). After 100milliseconds the timer expires and it is handled in the OnTimer() function. Now if i have to start a timer again with the same ID do i have to use KillTimer(ID1)?

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

                    nripun wrote:

                    SetTimer(ID1,100,NULL). After 100milliseconds the timer expires and it is handled in the OnTimer() function. Now if i have to start a timer again with the same ID do i have to use KillTimer(ID1)?

                    iT will Good Practice if you Call KillTimer(..) before setting the TImer on same ID... but as far as any Impact on Code concern, its Negligible !

                    "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