如何在 Metro Style App 中实现计时器 [英] How to Implement a timer in Metro Style App

查看:37
本文介绍了如何在 Metro Style App 中实现计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个游戏,我必须在其中实现计时器来显示已过去的时间.我该怎么做?

I am developing a game in which I have to implement timer for showing the time that has elapsed. How can I do that?

推荐答案

async/await 方式:

The async/await way:

private bool isTimerRunning;

private async void StartTimer()
{
    this.isTimerRunning = true;

    while (this.isTimerRunning)
    {
        OnOneSecondPassed();
        await Task.Delay(1000);
    }
}

private void StopTimer()
{
    this.isTimerRunning = false;
}

protected virtual void OnOneSecondPassed()
{
}

这篇关于如何在 Metro Style App 中实现计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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