Oliver Simith
Member
Hi, all. I was trying the following codes to learn Wait For and Sleep. However, I always failed to get the output right.
The code is like this:
The output is:
I expect "p1 ended" to be part of the output. However, The code after "Wait for p2" in subroutine p1 seems to have never been executed. When p2 is raised in Activity_create which means the requirement for resuming p1 is met, shouldn't subroutine p1 continue execution from where it is waiting?
If I change subroutine p2 to the following, just as the B4X Language Tutorial taught, then I will get the expected output.
So, is an explicit command like CallSubDelayed a must for the machine to get back to where it is waited for( In this case, the WaitFor in subroutine p1)?
I think I must have missed the point somewhere. Please tell me where I have misunderstood and any comment is appreciated. Thanks!
The code is like this:
my code:
'main
sub activity_create
p1
p2
end sub
private sub p1
log("p1 started")
Wait For p2
log("p1 ended") 'It seems that this line of code is always blocked by the Wait For command on the previous line
end sub
private sub p2
log("p2 started")
sleep(5000)
log("p2 ended")
end sub
The output is:
output:
p1 started
-p2 started
-p2 ended
I expect "p1 ended" to be part of the output. However, The code after "Wait for p2" in subroutine p1 seems to have never been executed. When p2 is raised in Activity_create which means the requirement for resuming p1 is met, shouldn't subroutine p1 continue execution from where it is waiting?
If I change subroutine p2 to the following, just as the B4X Language Tutorial taught, then I will get the expected output.
modified subroutine p2:
Private Sub p2
Log("-p2 started")
Sleep(5000)
Log("-p2 ended")
CallSubDelayed(Me, "p2") ' When this line is added, I got the expected output
End Su
'output I expected
p1 started
-p2 started
-p2 ended
p1 ended
So, is an explicit command like CallSubDelayed a must for the machine to get back to where it is waited for( In this case, the WaitFor in subroutine p1)?
I think I must have missed the point somewhere. Please tell me where I have misunderstood and any comment is appreciated. Thanks!