B4J Question CallSubDelayed timings

Chris2

Active Member
Licensed User
Longtime User
The tooltip for CallSubDelayed states "The sub will be called after the current code execution completes":
1766483886600.png


Does this mean that this:
B4X:
Sub UsingCallSubDelayed
    CallSubDelayed(mCallback, mEventName & "_Event2")
    .......
    Bunch of code that does loads of stuff
    .....
End Sub
is exactly the same as this?:
B4X:
Sub UsingCallSubDelayed2
    .......
    Bunch of code that does loads of stuff
    .....
    CallSubDelayed(mCallback, mEventName & "_Event2")
End Sub

And if so, is this true even if there are Wait For calls in the sub (which will make the sub Return)?
 
Solution
CallSubDelayed sends a message to the message queue. When the main thread is not busy running other code, it will process the message and execute that sub.

So without Sleep or Wait For, the two code snippets are equivalent.

A call to Sleep will cause the called sub to be executed.
Top