CancelTimer
This reference collection includes Vector documentation reproduced with permission. Snippets may require configuration-specific symbols and are not all standalone programs. Sources and validation limits.
Syntax
void cancelTimer(msTimer t);
void cancelTimer(timer t);
Stops an active timer. There is no return value. Cancelling the timer does not undo work already performed by its event handler or retract a frame already submitted for transmission.
Example: stop and restart a repeating task
The example uses explicit rescheduling with setTimer. Press s to start and x to stop. The running flag describes the intended task state; it is separate from the question of whether the timer currently has a pending expiration.
variables
{
msTimer tick;
int running;
}
on start
{
running = 0;
}
on key 's'
{
if (running) return;
running = 1;
setTimer(tick, 200);
}
on timer tick
{
if (!running) return;
write("Periodic task ran");
setTimer(tick, 200);
}
on key 'x'
{
running = 0;
cancelTimer(tick);
}
on preStop
{
running = 0;
cancelTimer(tick);
}
Verify that repeated s presses do not restart the schedule, x prevents the next scheduled action, and s can start it again. Treat an action already observed before cancellation as completed work, not a cancellation failure. See periodic transmission for a CAN example and isTimerActive for inspecting pending state.
Source and validation
API signatures and behavior follow the authorized Vector reference. The explanations and inspection examples are site guidance, not recorded CANoe test results. Check the installed help for your tool version and node type. See sources and validation limits.