Android Question When clicked, running a code twice

RodM

Member
Licensed User
I made a simple timer to test the Sleep function, as in code below, and noticed that when I click the label, it logs as if I have clicked it twice.
Could anyone tell me, please, why this happens?

B4X:
Private Sub Label3_Click
    IsRunning = Not(IsRunning)
    
    Do While True
        If Not(IsRunning) Then
            Log("Stop")
            Exit
        End If
        Label3.Text = DateTime.Time(DateTime.Now)
        Sleep(1000)
    Loop
End Sub
 

toby

Well-Known Member
Licensed User
Longtime User
It works as expected. When the execution reaches Sleep(1000), it pauses for 1 second, handling control over to the system. One second later, the execution resumes from where it left off, running the Do While loop the second time.
 
Upvote 0

RodM

Member
Licensed User
Thank you, toby!
I realized that, each time I click the label, it runs an instance of Sub Label_3_Click and, in that case, it can run two instances before stop.

Thank you.
 
Upvote 0
Top