Reputation:
In Raymond's example of how to use SetTimer
to distinguish single and double-clicks, he calls KillTimer
from within the timer callback function. I wasn't clear on why that would be necessary. Doesn't the fact that the callback is occurring mean that the timer has reached its endpoint?
Upvotes: 0
Views: 300
Reputation: 51413
Oddly enough, the documentation for SetTimer doesn't document its behavior. The behavior being that the call installs an auto-repeat timer.
However, you will find the following under timer operations:
Whenever the time-out value for the timer elapses, the system posts a WM_TIMER message to the window associated with the timer.
This API has no immediate support for one-shot timers. To implement a one-shot timer you have to call KillTimer when handling the first WM_TIMER
message.
Upvotes: 2
Reputation: 612993
Timers fire repeatedly at their specified frequency. You must call KillTimer
if you wish them to stop firing.
So a classic usage is to create a timer, and then kill it the first time it fires. That's known as a one shot timer.
Upvotes: 0