문제

The problem here is that dispatcher timer only activates once. This is shown in the UI's textbox as round times of the timer(1). I'd want it to activate all the time.

DispatcherTimer timer;
int timerRound=0;

public partial class AdventureMap : PhoneApplicationPage
{
    timer = new DispatcherTimer();
    timer.Interval = TimeSpan.FromMilliseconds(30);
    this.timer.Tick += new EventHandler(timer_Tick);
    this.Loaded += new RoutedEventHandler(timer_Tick);
}
void timer_Tick(object sender, EventArgs e)
{
    timerRound++;
    textBox.Text = "Timer updates! round " + timerRound;
}
도움이 되었습니까?

해결책

Your timer doesn't activate even once. In your code sample, the textbox is updated only by the Loaded event of your page. For your timer to work, you need to start it:

timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(30);
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top