Friday, March 5, 2010

Using the Dispatcher Timer


ShareThis

//In Dot Net Framework DispatcherTimer class is used to repeat some tasks after certain interval
//It is similar to the Timer Class used in VB 6
 
// Here we go
//Declare a DispatcherTimer Global Variable 
System.Windows.Threading.DispatcherTimer myDispatcherTimer;

//setup the timer- Use this code within the class constructor or any suitable place

myDispatcherTimer = new System.Windows.Threading.DispatcherTimer();
myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 2000); // in MS
myDispatcherTimer.Tick += new EventHandler(Each_Tick);
myDispatcherTimer.Start();

// event handler- place this within a class

public void Each_Tick(object o, EventArgs sender)
{
try
{
// Code the things here that you want to happen after a certain duration

}

catch (Exception ex)
{
}
}
 
 


0 comments: