Oliver Simith
Member
Hi all, I have a question regarding the sleep(milliseconds as int) statement.
According to the official tutorial, the sleep statement suspends the execution of the current subroutine and resumes it after a specified time. However, in the following demo, I found that the specified time doesn't seem to work.
I am posting B4J code, but the same is true for B4A.
The output is like this:
It seems that the test subroutine is continued after all the rest codes in the appStart routine have been executed which costs 18 milliseconds.
I am wondering if this is something wrong? Or is it a feature of b4x?
According to the official tutorial, the sleep statement suspends the execution of the current subroutine and resumes it after a specified time. However, in the following demo, I found that the specified time doesn't seem to work.
I am posting B4J code, but the same is true for B4A.
demo:
AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
Log("app start")
test
beginTime=DateTime.Now
Log("beginTime: " & beginTime)
Log(count)
'count will increase from 1 to 121
count=count+1
Log(count)
count=count+1
Log(count)
... ‘ I omitted most code here for simplification
Log(count)
count=count+1
Log(count)
count=count+1
Log(count)
count=count+1
Log(count)
count=count+1
Log(count)
count=count+1
Log(count)
count=count+1
Log(count)
count=count+1
Log(count)
count=count+1
Log(count)
count=count+1
Log(count)
count=count+1
endTime=DateTime.Now
Log("endedTime " & endTime)
Log("duration: " & (endTime-beginTime))
Log("max(count)=" & count)
End Sub
Private Sub test
Log("welcome to test")
Sleep(1)
Log("test ended")
End Sub
The output is like this:
output:
Waiting for debugger to connect...
Program started.
app start
welcome to test
beginTime: 1711369282467
1
2
3
4
...' I omitted most output lines here for simplification'
...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
endedTime 1711369282485
duration: 18
max(count)=121
test ended
It seems that the test subroutine is continued after all the rest codes in the appStart routine have been executed which costs 18 milliseconds.
I am wondering if this is something wrong? Or is it a feature of b4x?