定时器恢复逻辑 [英] Timer Resume Logic

查看:114
本文介绍了定时器恢复逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使DispatcherTime暂停,然后从以编程方式暂停的位置重新启动?

How can I make the DispatcherTime to pause and then restart from where paused programatically?

推荐答案

我会每秒运行DispatcherTimer。 有一个你没有暂停时增加的变量。

I would have DispatcherTimer run every second.  Have a variable that you increment when not paused.

例如:

if(!bPaused)
   iTick++;

if(iTick == threshold)
{
   iTick = 0;
   // do something here.
}

如果要暂停生成的操作,请将bPaused设置为true。 计时器仍将触发,但不会激活任何结束操作。

When you want to pause the resulting action from happening, set bPaused to true.  The timer will still fire, but won't activate whatever is the end action.

将阈值设置为DispatcherTimer间隔的数量。 如果DispatcherTimer的间隔为1秒,并且您希望每10秒钟发生一次,则阈值应设置为10.

Set threshold to the number of DispatcherTimer intervals.  If DispatcherTimer's interval is 1 second, and you want something to happen every 10 seconds, threshold should be set to 10.


这篇关于定时器恢复逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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