I have a DispatcherTimer
in my WPF application that updates text within the application every 200 milliseconds. The program displays a series of counters, clocks and timers.
private DispatcherTimer dispatch = new DispatcherTimer();
public Timer()
{
InitializeComponent();
this.dispatch.Interval = TimeSpan.FromMilliseconds(200);
this.dispatch.Tick += new EventHandler(updateTimer);
}
private void updateTimer(object sender, EventArgs e)
{
loadingImage.RenderTransform = new RotateTransform(counter * 36);
counter++;
try
{
clock.Text = DateTime.Now.ToString(@clockFormat.Text);
}
catch (Exception) { }
try
{
watch.Text = watchCounter.Elapsed.ToString(@watchFormat.Text);
}
catch (Exception) { }
}
The problem I am having is whenever the DispatcherTimer
is running, it causes a "stutter" in my application. Its as if everytime it runs the event handler, the program lags a little bit. Is there a way to get rid of this lag?