管理计时器滴答事件在另一个计时器滴答 [英] Manage timer tick event on Another timer tick

查看:140
本文介绍了管理计时器滴答事件在另一个计时器滴答的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序读取标记然后根据它进行处理。目前我已将计时器设置为每秒刻度,并且在该刻度事件上调用函数(包括从数据库中显示的图像)。

但是现在我想在另一个滴答事件上管理滴答事件,即倒计时器。我希望第一个计时器按原样勾选,但是如果第一个计时器重复读取相同的标签并且如果时间超过2分钟,则添加新的计时器以维持倒计时,然后从表单中清除图像。如果在此之前,第一个计时器刻度获得一个新标签,而不是替换当前图像中的上一个图像...



现在问题是来管理两个计时器目前的要求。

任何线索,帮助,指导这方面的任何事情都将受到衷心的接受。并提前感谢。

I have an application that reads a tag and then process according to it. Currently I have set the timer to tick for per second and the function(includes Image shown from database accordingly) is called on that tick event.
But now I want to manage that tick event on another tick event i.e for count down timer. I want the first timer to tick as it is but to add a new timer to maintain count down if the first timer reads the same tag repeatedly and if time elapses more than 2 minutes then clear the image from the form. And if before that the first timer tick gets a new tag than replace the previous image from the current one...

Now the problem is coming to manage both timer with current requirements.
Any clue, help, guide any thing in this regard will be heartly accepted. And thanks in advance.

推荐答案

另一个计时器则是一种超时观察者。它的工作方式如下:



1)启动timeoutTimer。



2)让你的firstTimer工作为通常,



3)另外在一些成员变量中保存标签的副本。



4)在firstTimer的Tick事件中,让它检查标记是否已更改,如果是,请重置timeoutTimer。因此,每当firstTimer打勾时,它都会推迟timeoutTimer的Tick。只要firstTimer在timeoutTimer的间隔内没有做某事,就会调用它的事件处理程序。



5)在timeoutTimer的Tick事件中,做任何超时要求的事情。
The other timer then is a sort of "Timeout watcher". It works something like this:

1) Start timeoutTimer.

2) Let your firstTimer work as usual,

3) Plus save a copy of the tag in some member variable.

4) Within firstTimer's Tick event, let it check if tag has changed and if so, reset timeoutTimer. So whenever firstTimer ticks, it postpones timeoutTimer's Tick. Just if firstTimer fails to do something within timeoutTimer's interval, its event handler is called.

5) On timeoutTimer's Tick event, do whatever the timeout requires to be done.


我只使用一个计时器和一个状态机 [ ^ ]在tick事件处理程序内。
I would use just one timer and a state machine[^] inside the tick event handler.


这篇关于管理计时器滴答事件在另一个计时器滴答的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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