I needed to call the sub that triggers the timer from two different places and circumstances. (pseudo code below)
The first is a Touch and so will be awaiting an event. OK
The second is in a recursive system and needs code following the timer triggering.
It did NOT work and analysis showed that it was 'probably' because once the timer was enabled the following code continued, before the timer triggered to run its own code. Thus the following code ran before the timer code, out of proper sequence.
I solved this by adding the following in Sub B...
Do While Timer.enabled
DoEvents
Loop
It does let the code run in correct sequence and the result works, but I am concerned that it may be 'cheating' and something will go wrong at some point as yet untested.
Any confirmation that this is 'legal' and that no problems should arise will be most gratefully received. Any suggestions that it is wrong, will be received
The first is a Touch and so will be awaiting an event. OK
The second is in a recursive system and needs code following the timer triggering.
It did NOT work and analysis showed that it was 'probably' because once the timer was enabled the following code continued, before the timer triggered to run its own code. Thus the following code ran before the timer code, out of proper sequence.
I solved this by adding the following in Sub B...
Do While Timer.enabled
DoEvents
Loop
It does let the code run in correct sequence and the result works, but I am concerned that it may be 'cheating' and something will go wrong at some point as yet untested.
Any confirmation that this is 'legal' and that no problems should arise will be most gratefully received. Any suggestions that it is wrong, will be received
B4X:
Sub pnl_Touch(...)
C 'Triggers timer which performs some slow actions by repeated ticks
End Sub
Sub B 'THIS IS RECURSIVE
C 'When this starts the timer, the code...
Do While Timer.enabled 'Added to wait for Timer??
DoEvents
Loop
more stuff '...continued here because the timer
End Sub ' has not yet triggered.
Sub C
...
If ... Then
count=20
Timer.enabled=True
End If
...
End Sub
Sub Timer_Tick 'one of 20 cycles
If count>0 Then
count=count-1
some action
Else
Timer.enabled=False
...
B 'this will retrigger timer via C
...
End If
End Sub