Android Question How to Pause For Next Loop Until Variable Set?

woodpecker

Member
Licensed User
Longtime User
I'm trying to pause a for next loop until a global variable called status is set to 1.

The global status variable gets set with Astreams_Newdata if the correct data is received.

I've tried things like :-

B4X:
Do Until status = 1
     Sleep(0)
Loop

I've also tried a couple of different delay subs but none seem to really work correctly, like these:-

B4X:
Sub Delay(Time As Long)
    Dim jo As JavaObject
    jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(Time))
End Sub

Sub Wait(ms As Int)
    Dim n As Long = DateTime.Now + ms
    Do While DateTime.Now < n
    Loop
End Sub
 

woodpecker

Member
Licensed User
Longtime User
The first code should work. However you should increase the sleep interval. Setting it to 0 like this can fill the message queue and slow down other events.
Start with 100.

Thanks Erel, does 100 mean it will pause for 100ms or only until status is set to 1?
 
Upvote 0
Top