1

How disable DispatcherTimer auto firing events and fire events manually?

Pragmateek
  • 13,174
  • 9
  • 74
  • 108
user3274485
  • 109
  • 1
  • 8

1 Answers1

5

Just call Stop() or set IsEnabled = false in the Tick handler:

DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += TimerTick;
timer.Start();
...

private void TimerTick(object sender, EventArgs e)
{
    ((DispatcherTimer)sender).Stop();
    ...
}
Clemens
  • 123,504
  • 12
  • 155
  • 268