Starting A Timer After Another Timer

I cannot figure out how to start a timer right after another timer completes. The sample projects for timers and the docs don’t cover this (that I could find).

Basically, I have a countdown timer that counts down from a variable amount. Once it’s done, another timer should start up, which the user will then cancel at some point with a button click.

I’ve got the first timer running fine. Whenever I try to add the second timer, all heck breaks loose. X)

How are you currently doing this? With Timers on a view, instantiating timers and using AddressOf, or by using Timer.CallLater? What code are you using within TimerA to start TimerB? What is the issue you’re seeing?

Currently, I have a timer associated (attached) to a Window. I am calling


to get it going.

The code inside simply counts down from an initial value derived from an on-window label and displays that result, down to zero, at which time it displays “Go!” Then it should start counting up.

The way I’m doing it now is I have a boolean called useCountdown set to True when CountdownTimer.Reset is first called. After the countdown reaches zero, I set that to false, and another part of the code now starts counting up… fortunately, they both use a 1000ms interval.

Is there a better way to accomplish this?

As of now, I’m having a problem when I re-trigger the Timer. It starts to countdown the second time, but halts after a second or two. But, that is less important than getting the actual usage of multiple timers correct in the first place.

Thank you!

Guessing at what your code looks like, I created a Window with the following properties:

useCountdown as Boolean = True valueTime1 as Integer valueTime2 as Integer

The following controls:
CountdownTimer as Timer
PushButton1 as PushButton
Time1 as Label
Time2 as Label

I have CountdownTimer’s properties set as follows:
Run Mode = Off
Period = 1000

In Timer1.Action I have the following:

[code]if useCountdown then
valueTime1 = valueTime1 - 1
if valueTime1 = 0 then
useCountdown = False
end if
elseif not useCountdown then
valueTime2 = valueTime2 - 1
if valueTime2 = 0 then
CountdownTimer.mode = 0
end if
end if

Time1.Text = Str( valueTime1 )
time2.Text = Str( valueTime2 )[/code]

In PushButton1.Action I have the following:

valueTime1 = 10 valueTime2 = 10 useCountdown = True CountdownTimer.Mode = 2

Clicking the button seems to show the timer working as expected.

@Anthony Cyphers Thank you for the sample code. I will compare it to what I have to see if I can get a clue.

I’m running into either a flaw with my algorithm or a bug. I suspect it’s the former. :slight_smile: