- Visual Studio 2012
- MS-LPL
- C#
- Windows 8
- Visual Studio 2012
- Windows 8 Store Apps
- Windows Store app
- A Timer for windows8 App
- 05/04/2013
Explicitly there is no Timer control in VS2012 for windows store apps. This Sample gives a solution for this, by implementing a simple timer.
Description
A timer can be created with the help of the DispatcherTimer class.
Main Functionality:
For every n seconds (you specify as the timer interval), the Tick event is Fired untill the timer is stopped.
Many of the young developers having doubts related to timer like,
How to implement a Timer in windows8 App?
How to start and stop a Timer ?
The sample gives answer to all timer related questions in a simple and easy way.
Only a few steps in implementation,
1, Create a object for the DispatcherTimer class.
2,Associate a Event "Tick" with the created object using the below code.
timer.Tick += timer_Tick();
3,Set a timer Interval for which periodically the Tick event is Fired(when the Timer is On) using the below line.
timer.Interval = TimeSpan.FromSeconds(5);// here is set the interval as 5 seconds
4, Then define the timer_tick method according to your own usage(In my sample i just displayed the time consumed).
private DispatcherTimer timer; private int i,j; timer = new DispatcherTimer(); timer.Tick += timer_Tick; timer.Interval = TimeSpan.FromSeconds(i); void timer_Tick(object sender, object e) { TimerTextBlock.Text = "Time Consumed: " + (i) + " second(s)"; i = i + j; }
Only a few steps in implementation,
1, Create a object for the DispatcherTimer class.
2,Associate a Event "Tick" with the created object using the below code.
timer.Tick += timer_Tick();
3,Set a timer Interval for which periodically the Tick event is Fired(when the Timer is On) using the below line.
timer.Interval = TimeSpan.FromSeconds(5);// here is set the interval as 5 seconds
4, Then define the timer_tick method according to your own usage(In my sample i just displayed the time consumed).