强制计时器计时(包括异步行为)
在我的应用程序中,我有一个计时器,它每隔几分钟检查一次来自服务器的配置更新。
配置检索是一个相当耗时的过程,所以我想强制计时器的“Tick”事件,但我不能只调用timer_tick(bla,bla,bla),因为它将同步执行。
有没有一种简单的方法可以强制计时器“滴答”(无需创建新线程)? 该行为应该“重置”计时器的剩余时间(因此,如果计时器最初设置为 2 分钟间隔,并且已经过去 1 分钟 - 强制“滴答”后 - 计时器将再次开始计时 2 分钟)
On my application I have a timer that checks for configuration updates from the server in a few minutes intervals.
The configuration retrieval is a pretty time consuming process, so I want to force the timer's "Tick" event, but I cannot just call the timer_tick(bla,bla,bla) because it will execute synchronously.
Is there a simple way to force the timer to "Tick" (without creating a new thread)?
The behavior should "reset" the time-left of the timer (so, if originally the timer was set to 2 minutes interval and 1 minute already past - after forcing the "Tick" - the timer will start counting 2 minutes again)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
改变它的超时值。
change it's timeout value.
在您的消费过程中,您的第一步只是禁用计时器,最后一步是再次启用它。
也许您只是在调用长时间运行的进程之前和之后放置此 dis- 并启用,如下所示:
Within your consuming process your first step is just to disable the timer and the last step is to enable it again.
Maybe you just put this dis- and enable just before and after calling your long running process like this: