Timers in VC++
-
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)?
-
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)?
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]--
-
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)?
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.
-
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)?
From the docs for
::SetTimer
. Holds true forCWnd::SetTimer
too...If the
hWnd
parameter is notNULL
and the
window specified byhWnd
already has a timer with the value
nIDEvent
, then the existing timer is replaced by the new timer.
WhenSetTimer
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
-
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.
It is still good practice to kill the old one though. The tigress is here :-D
-
It is still good practice to kill the old one though. The tigress is here :-D
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). :)
-
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). :)
HAND wrote:
(e.g. TerminateThread). :)
:shudderrrrrrr: :eek::( It's the UnderTaker...Run
Nibu thomas Software Developer Faqs by Michael dunn
-
HAND wrote:
(e.g. TerminateThread). :)
:shudderrrrrrr: :eek::( It's the UnderTaker...Run
Nibu thomas Software Developer Faqs by Michael dunn
-
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)?
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