How to Implement a timer in Metro Style App

拈花ヽ惹草 提交于 2019-12-21 17:37:07

问题


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


回答1:


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()
{
}



回答2:


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.



来源:https://stackoverflow.com/questions/10410072/how-to-implement-a-timer-in-metro-style-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!