We have quite often come across scenarios where-in we need to execute certain client-Side code at certain intervals .
at certain intervals of time .
The Sys.Preview.Timer Provides an abstraction over these functions and makes it easier to define Functions to be Executed at certain
You need to include the Script file "PreviewScript.js" to have access to the Timer Control .
Instantiating the Timer control :
var clientSideTimer = new Sys.Preview.Timer();
By default , once instatiated , the Timer is disabled .
Enable The Timer
clientSideTimer.set_enabled( true );
Set the Interval for the timer :
The Interval is measured in milliseconds
clientSideTimer.set_interval( 1000 );
Add a function to be called at the interval
You add the function to be called at the interval by running
clientSideTimer.add_tick( OnTimerTick );
The Parameter "OnTimerTick" is a function that is executed at the Interval specified.
You can add multiple Functions to be callled at the interval.
The functions are executed at the interval in the same order that they are added using add_tick.
Stop the Timer
Disable the Timer to stop the Timer Entirely.
clientSideTimer.set_enabled( false );
Alternatively , you can stop certain functions being called by calling the "remove_tick" Method on the Timer.
clientSideTimer.remove_tick( OnTimerTick );
Check out the Sample attached to get a view of how the control works and how you can use it .
Whats Missing :
The main pain point I see in using the Timer Control is that I cannot pass a context to the Functions called at the "Tick" event.
The reason this happens is because ..
The Function that returns the callback to the "Tick" event passes "Sys.EventArgs.Empty" to the callback.
You can customize the Script to enable the functionality of passing a context to the Timer Callback.
We will discuss that in a future post .