强制计时器计时(包括异步行为)

发布于 2024-08-31 16:19:10 字数 248 浏览 1 评论 0原文

在我的应用程序中,我有一个计时器,它每隔几分钟检查一次来自服务器的配置更新。

配置检索是一个相当耗时的过程,所以我想强制计时器的“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巷子口的你 2024-09-07 16:19:11

改变它的超时值。

change it's timeout value.

浅紫色的梦幻 2024-09-07 16:19:11

在您的消费过程中,您的第一步只是禁用计时器,最后一步是再次启用它。

也许您只是在调用长时间运行的进程之前和之后放置此 dis- 并启用,如下所示:

timer.Enabled = false;
LongRunningSyncProcess();
timer.Enabled = true;

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:

timer.Enabled = false;
LongRunningSyncProcess();
timer.Enabled = true;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文