Question

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;
}
Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top