I have read this statement:
I think that you cannot use Sleep(0) as an alternative to DoEvents, because anyway, even setting to 0 the duration of the sleep, control wil be returned (for micro-seconds, probably) to the calling routine.
An (stupid) example:
The result of this code is not what you wanted. If you use DoEvents (I tried also using VB.NET) you get the "right" behavior.
You can call Sleep(0) for the shortest pause. This can be used to allow the UI to be refreshed. It is a good alternative to DoEvents (which doesn't exist in B4J and B4i and should be avoided in B4A).
I think that you cannot use Sleep(0) as an alternative to DoEvents, because anyway, even setting to 0 the duration of the sleep, control wil be returned (for micro-seconds, probably) to the calling routine.
An (stupid) example:
B4X:
Sub Activity_Resume
For i = 1 To 10
LogColor("I : " & i, Colors.Red)
Show
Next
End Sub
Sub Show
For j = 1 To 100
Label1.Text = j
LogColor("J : " & j, Colors.Blue)
Sleep(0)
Next
End Sub
The result of this code is not what you wanted. If you use DoEvents (I tried also using VB.NET) you get the "right" behavior.
Last edited: