且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

强行停止计时器嘀嗒事件

更新时间:2023-12-04 08:41:52

timer1.stop

timer2.stop



这应该这样做。如果您在此之后仍然触发最后一个计时器事件,则尝试在按钮中将公共布尔值设置为false,然后在计时器事件的开头检查它。如果它是假的(或者你设置的任何东西),那么退出计时器事件。



- Pete






AFAIK你可以用 Timer.Stop [ ^ ]。

当然,此解决方案假设您可以通过按钮代码直接访问计时器对象。

但是即使你必须等待1分钟,问题是什么?

计时器在嘀嗒事件发生之前什么都不做。





欢呼,

Marco


i have two timers
timer1 is slow , tick time of 1 min
while timer2 needs to be extremely fast , tick time of 10 milliseconds

each have separate tick time

now in i have created a button to stop all working and it should also stop timer from working

but as timer1 tick time is 1 min , i have to wait until 1 min till timer really stops

also the problem is some times code in timer2 tick event can not be complete in 10 milliseconds so whole event is overlapping . it''s fine overlapping in working but if i press stop button then all overlapped timer events also must be stopped

how to do this ?

timer1.stop
timer2.stop

This should do it. If you''re still getting one last timer event firing after that, then try setting a public boolean to false in your button, and then check for it in the beginning of your timer events. If it''s false (or whatever you set it to look for), then exit the timer event.

- Pete


Hi,

AFAIK you can directly stop a timer using Timer.Stop[^].
Of course, this solution supposes that you have direct access to your timer object from the button code.
But even when you have to wait 1 min, what is the problem?
The timer ain''t does nothing until the tick event comes up.


cheers,
Marco