Using a timer RRS feed

  • Question

  • There is no timer control in blend 2...

    I need to use a timer to decrease the number in a label, one each second... when it reaches zero, it returns to a specific number, again and again...

    I just feel its hard to do with a storyboard...
    Thursday, August 28, 2008 12:20 PM


  • Hi Rurushu,

    We have class called DispatcherTimer, which does the job of the timer control.

    Sample Code:

    using System.Windows.Threading;

    public partial class UsingTimer

    private DispatcherTimer timer;

    void StartTimerButton_Click(object sender, RoutedEventArgs e)
    timer =
    new DispatcherTimer();
    timer.Interval =
    timer.Tick +=
    new EventHandler(timer_Tick);

    void timer_Tick(object sender, EventArgs e)
    // Write your code here, that need to be executed every 1 sec

    Hope this answers your question.


    • Proposed as answer by BalaMurugan_Sa Saturday, August 30, 2008 12:26 PM
    • Edited by BalaMurugan_Sa Saturday, August 30, 2008 12:26 PM Missed closing brace
    • Marked as answer by Rurushu Sunday, August 31, 2008 8:44 AM
    Saturday, August 30, 2008 12:25 PM