Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.
Implement timers in Windows Phone
This article explains how to implement a timer (DispatcherTimer) in Windows Phone.
The code example shows how to use DispatcherTimer on Windows Phone. Timers are very useful for executing code at specified time intervals.
The code in this article is written using C#. A text box will be used to display a clock, which is refreshed every second. Follow the below steps to create the clock app:
- Create a new "Silverlight" project using C# language. Here we are naming the project as "Clock"
- Place a text box and a button.
- We are giving textbox name as "txtClock". We can also change the font and color of content in the text box.
- We will now add following code to the project.
public partial class MainPage : PhoneApplicationPage
void OnTimerTick(Object sender, EventArgs args)
// text box property is set to current system date.
// ToString() converts the datetime value into text
txtClock.Text = DateTime.Now.ToString();
private void button1_Click(object sender, EventArgs e)
// creating timer instance
DispatcherTimer newTimer = new DispatcherTimer();
// timer interval specified as 1 second
newTimer.Interval = TimeSpan.FromSeconds(1);
// Sub-routine OnTimerTick will be called at every 1 second
newTimer.Tick += OnTimerTick;
// starting the timer
Building and Running
The application is now ready to be built (Ctrl+Shift+B) and ran (Ctrl+F5) either on the emulator or a device.
This application has been tested on the emulator, and should work on a physical device.