W woodpecker Member Licensed User Longtime User Jun 9, 2018 #1 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 :- Code: 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:- Code: 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
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 :- Code: 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:- Code: 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
LucaMs Expert Licensed User Longtime User Jun 9, 2018 #2 The "correct" way is to use Resumables (wait for the event Astreams_Newdata, which I don't know, I never used this stuff) Upvote 0
The "correct" way is to use Resumables (wait for the event Astreams_Newdata, which I don't know, I never used this stuff)
Erel B4X founder Staff member Licensed User Longtime User Jun 10, 2018 #3 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. Upvote 0
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.
W woodpecker Member Licensed User Longtime User Jun 10, 2018 #4 Erel said: 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. Click to expand... Thanks Erel, does 100 mean it will pause for 100ms or only until status is set to 1? Upvote 0
Erel said: 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. Click to expand... Thanks Erel, does 100 mean it will pause for 100ms or only until status is set to 1?
Erel B4X founder Staff member Licensed User Longtime User Jun 11, 2018 #5 Nothing is paused. It means that the code in that sub will continue after 100ms. If it is too much then change it to 10. The user will never notice it. Upvote 0
Nothing is paused. It means that the code in that sub will continue after 100ms. If it is too much then change it to 10. The user will never notice it.