Skip to content
This repository was archived by the owner on Feb 20, 2021. It is now read-only.

Files

Latest commit

author
Terry Fei (Pactera)
Nov 12, 2019
3e88636 · Nov 12, 2019

History

History

A Simple Timer for windows8 App C#

A Simple Timer for windows8 App C#

Requires

  • Visual Studio 2012

License

  • MS-LPL

Technologies

  • C#
  • Windows 8
  • Visual Studio 2012
  • Windows 8 Store Apps
  • Windows Store app

Topics

  • A Timer for windows8 App

Updated

  • 05/04/2013

Description

Introduction

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).



 

 

C#
Edit|Remove
csharp
  
        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; 
        } 
 
      

Source Code Files

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).