Showing the time

konisek

Member
Licensed User
Longtime User
Can you advise how to make actual time being displayed regardless on other running processes?
When I use timer and timer tick (see the code), it runs well. But when I run other processes in the code (like sending/receiving data), the time is stopped and starts again till the process is completed. It looks like when program is "busy", the timer is stopped for the "busy" time. I want to push the timer to the top priority. I tried DoEvents but no effect. Or is there any other way to show the time?
B4X:
Sub App_Start
Form1.Show
Timer1.Interval = 1000
Timer.Enabled = true
TimerFormat("HH:mm:ss")
End Sub

Sub Timer1_Tick
label1.Text = time(now)
End Sub
 

agraham

Expert
Licensed User
Longtime User
No, only one thread, the main one that starts when your program starts, is allowed to draw to the screen. When this thread is not running code it is waiting for messages caused by events to arrive. The timer sends messages periodically that cause the main thread to run your timer code. DoEvents should work if called in a "busy" bit of code, most likely a loop, as it looks to see if there are any messages to process and if so does. If DoEvents does not work it is likely that your code is actually blocked waiting on a synchronous read or write. The only solution is to place the blocking code in a separate thread using my Threading library.

If you are using the HTTP library it offers asynchronous methods that run the blocking calls on a separate thread to overcome this sort of problem.
 
Top