强行停止计时器嘀嗒事件 [英] forcefully stop timer tick event

查看:122
本文介绍了强行停止计时器嘀嗒事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个计时器

timer1很慢,滴答时间为1分钟
而timer2需要非常快,滴答时间为10毫秒



每个都有单独的勾选时间



现在我已经创建了一个按钮来停止所有工作,它也应该停止计时器工作



但是当timer1的滴答时间为1分钟时,我必须等到1分钟,直到计时器真正停止



也问题是有时候timer2 tick事件中的代码在10毫秒内无法完成,因此整个事件是重叠的。它在工作中很好重叠,但如果我按下停止按钮,那么所有重叠的计时器事件也必须停止



怎么做?

解决方案

timer1.stop

timer2.stop



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



- Pete


< blockquote>



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


这篇关于强行停止计时器嘀嗒事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆