
[英]WP7/8 Call a DispatcherTimer tick event in the background/lock screen
[英]DispatcherTimer and real time WP7
我正在创建一个老虎机游戏。 当我获得胜利时,我想使它显示在我的TextBlock中,从0开始计数。 为了创建我正在使用DispatcherTimer。
问题是,例如当我的整数赢= 50,并且在TextBlock中使用DispatcherTimer之后,我看到超过50,例如54、56。
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 0, 0, 200);
timer.Tick += new EventHandler(Timer_Tick);
if (win != 0)
{
timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
if (timerCount == win)
{
timer.Stop();
}
WinTextBlock.Text = timerCount.ToString();
timerCount++;
}
确保在开始时将timerCount分配为0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.