I want to run timer countdown (DispatchTimer) multiple times in a loop, one after another. I want to wait until one timer stops and then run another one.
I'm gonna try something like this:
public TimeSpan CurrentTimeSpan;
private void RunInterval()
{
for (int i = 0; i < 10; i++)
{
RunTimer(new TimeSpan(0, 0, 0, 30));
}
}
private void RunTimer(TimeSpan Timer)
{
DispatcherTimer timer1 = new DispatcherTimer();
timer1.Interval = new TimeSpan(0, 0, 0, 1);
CurrentTimeSpan = Timer;
timer1.Tick += Timer1OnTick;
}
private void Timer1OnTick(object sender, object o)
{
DispatcherTimer timer = (DispatcherTimer) sender;
CurrentTimeSpan = CurrentTimeSpan.Subtract(timer.Interval);
if (CurrentTimeSpan.TotalSeconds == 0)
{
timer.Stop();
}
}
My problem is that method RunInterval or RunTimer doesn't wait until timer will stop.
What can I do about it?