I need a timer that redirects me to another page after 5 seconds, the problem is that it redirects me to this page every 5 seconds, so I need to stop it. If I stop It after tmr.Start() It doesn’t execute the event. How can I do this in the event OnTimerTick?
DispatcherTimer tmr = new DispatcherTimer();
tmr.Interval = TimeSpan.FromSeconds(5);
tmr.Tick += new EventHandler(OnTimerTick);
tmr.Start();
void OnTimerTick(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/lvlSet1/s1lvl3.xaml", UriKind.Relative));
}
Description
Two possible solutions.
DispatcherTimerinstance on class level, not in your method. Then you can acces them from yourOnTimerTickMethod.DispatcherTimerin yourOnTimerTickmethod.Sample
1. Solution
2. Solution
More Information
MSDN: DispatcherTimer Class