Implementing a pause

rfsingh81

Member
Licensed User
Longtime User
How do you implement a pause after something?
I am writing data to
B4X:
Astream.Write ("abcabc")
I would like this data to be sent again after let us say 25mS. How do I achieve that?
 

KitCarlson

Active Member
Licensed User
Longtime User
I use a Timer for that, but I find less than 100mS, has timing jitter on my devices. I place the Astream.Write in the Timer sub.

It is also possible to disable the timer, and change the value, and enable.

There is a timer example in user guides.
 
Upvote 0

rfsingh81

Member
Licensed User
Longtime User
I need more like a pause statement. I do not have one statement, I actually have nearly 10-12 statements in my code. Having timer to do it will be complicated. Thanks
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
one hundred milliseconds is an extremely short time.

twenty five milliseconds?

You are not getting in the zone dude :)
 
Upvote 0

rfsingh81

Member
Licensed User
Longtime User
ok, given the circumstances, I will try to work with the shortest time. How it can be implemented as a pause?
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
You can create a sub (private or public) and call it with the time you want.



B4X:
.........
........
........

Astream.Write ("abcabc")
Sleep (25)

...........
..............
..............


Sub Sleep(milliseconds As Long)
  
   Dim t, Actual As Long
   
   Actual = DateTime.Now
   t= Actual
   
   Do Until (t-Actual) >= milliseconds
      t= DateTime.Now
      DoEvents
        Loop  

End Sub

regards

Jesus
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
These guys have the right idea in using a Timer.

The Timer, depending on what you call it will have a :

Sub MyTimer_Tick

End Sub

And the beauty of the Timer is that it works in it's own thread.

So it doesn't block the main thread.

It is 'non-blocking'

One thing to keep in mind then is that as soon as you enable the timer, off it ticks on it's own thread and when it counts down to zero depending on the number of milliseconds that you have set it to, it will fire the MyTimer_Tick Sub.

You must program with this in mind and put the code that you wish to run when the Timer count's down to zero in that MyTimer_Tick subroutine and it is often the case that you will include a MyTimer.Enabled = False line in that subroutine and somewhere else in your code you will put a MyTimer.Enabled = True to fire it off.

The MyTimer_Tick subroutine can be seen as an interrupt driven subroutine

Rather cool :)
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
A paused activity mainly means that no control events are triggered.
The easiest way, in my opinion, to achieve this, without blocking the thread, is to place a transparent panel, bring it to front, consume its click/touch, and run a timer to continue the way you want. When finished, hide the panel.
 
Upvote 0
Top