0

i have a problem with a application. this application simply shows a number value every second. you can see it as a countdown. the problem is, that this Timer sometimes stop to tick and i dont know why. where is my code:

public MainPage()
{
    InitializeComponent();

    Loaded += new RoutedEventHandler(MainPage_Loaded);
}

i start the timer afte the Loaded event:

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    Timer t1 = new Timer(TimerCall);
    t1.Change(0, 1000);
}

and here is the method which chanes the text:

private void TimerCall(object state)
{
     TextField.Dispatcher.BeginInvoke(delegate
    {
        TextField.Text = "some text change";
    }); 
}

I dont understand why this sometimes stops

2
  • 2
    Have you tried DispatcherTimer? It already does the Invoking and might be more suitable.
    – dowhilefor
    Jan 25, 2012 at 11:03
  • I'm not a wp developer, but at first glance it appears that t1 should be declared in the class scope. Jan 25, 2012 at 11:14

1 Answer 1

0

Have a look at this article especially the section on The Tombstone

Next to the fact that the Timer is a local variable instead of a class member, you might be running into the tomb stoning process. The article explains this quite well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.