When working on WPF or Silverlight Applications, instead of using your typical .Net timers, developers should stick with the DispatcherTimer. Handlers for the DispatcherTimer are invoked on the UI thread, so you don't have to worry about threading issues. The DispatchTimer class is located in the System.Windows.Threading namespace. To use it, you set an Interval property from a TimeSpan property, add a handler for the Tick event and call the start method to start the timing.
//------------------------------------------
//DispatcherTimer code snippet
//------------------------------------------
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(100);
timer.Tick += timerOnTick;
timer.Start();
void timerOnTick(object sender, EventArgs args)
{
//do something
}
Showing posts with label dispatcherTimer. Show all posts
Showing posts with label dispatcherTimer. Show all posts
Wednesday, July 16, 2008
Subscribe to:
Posts (Atom)