Greeting.
How do I make an application wait n seconds.
Thank you.
How do I make an application wait n seconds.
Thank you.
You are not allowed to pause the main thread".
Sub Sleep(ms As Long)
Dim now As Long
If ms > 1000 Then ms =1000 'avoid application not responding error
now=DateTime.Now
Do Until (DateTime.Now>now+ms)
DoEvents
Loop
End Sub
At times, it makes sense to simulate a "program is working" state just for some milliseconds, when interacting with the user.
In these cases i use the following function, which seems to work fine:
B4X:Sub Sleep(ms As Long) Dim now As Long If ms > 1000 Then ms =1000 'avoid application not responding error now=DateTime.Now Do Until (DateTime.Now>now+ms) DoEvents Loop End Sub
Is this bad programming style?
Yes. Bad practice.
sleep(100)