How to Implement a timer in Metro Style App

2019-04-10 15:20发布

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

2条回答
一纸荒年 Trace。
2楼-- · 2019-04-10 16:12

Did you try to use DispatcherTimer in namespace Windows.UI.Xaml?

If this Timer doesn't fit to your needs, please describe why and what your requirements are.

查看更多
祖国的老花朵
3楼-- · 2019-04-10 16:23

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()
{
}
查看更多
登录 后发表回答