I have an application where a service is collecting data from a bluetooth source (using AsyncStreams). The data is to be processed and displayed on a bitmap which can, depending on the latest data values, take some time to redraw - on occasions longer than the interval between BT updates.
I presume that the service can pre-empt the GUI code so it is not particularly safe to use a global map or list where the service adds data and the GUI reads and displays it.
Is there a locking mechanism that I can use or should I send new packets of data to the GUI using callsubdelayed and hope that the GUI does not get too many packets behind the data gathering?
I have a GUI sub responding to a CallSubDelayed from a service that receives new data over bluetooth. The GUI sub can take up to 1 second to recalculate and draw the new data on a bitmap then Gaussian blur and display it.
The service has a timer tick sub (100ms period) which is supposed to requests new data on a time basis (normally about every 0.5s) and an AsyncStream new data sub to receive the data.
Is it the case that once the GUI sub runs the service will not respond to the timer tick until the GUI has finished (returned) thus making some of the requests having a longer gap than others.
Would DoEvents in the GUI sub be needed to allow the service to run and keep some accuracy in its timing?
Thanks for the update, I had avoided the threading library because of the warnings that it should not be used for GUI manipulation. Presumably though this only applies to code such as the final drawing of a bitmap on a canvas initialised to a panel. Is the earlier creation of the bitmap using code like this safe in a thread?
B4X:
Sub CreateScaledBitmap(Original As Bitmap, width As Int, height As Int, Filter As Boolean) As Bitmap
Dim r As Reflector
Dim B As Bitmap
B = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
Array As Object(Original, width, height, Filter), _
Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
Return B
End Sub
As an alternative, would a chain of CallSubDelayed be a way of allowing other events to be processed in the thread (does the callsubdelayed put the run request at the end of the queue of events that would be building up on my thread)?