问题
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