Android Question Astream_NewData Timing

lip

Active Member
Licensed User
Longtime User
My question is: Astream_NewData presumably interrupts whatever else is going on. Does it run at the end of the running Sub, or at the end of the running program command line? Or at some other point?

My program creates a queue of commands in a SQLite database (database initialized in Starter activity). These commands are sent via Bluetooth. Bluetooth Serial is initialized in a service. Every Bluetooth command gets a response which is processed, then the next command is sent.

The main activity might use a For...Next loop which generates, say 500 commands. The first one is sent as it is created then subsequent commands are sent as the previous reply is received.

This means that commands are being created, sent and replied to and processed concurrently. Commands typically get a response after 150mS. The next command seems to get sent about 20mS after the last one is received.

All generally works well but every few hundred commands there is a blip when things seem to get out of sync. I do not intentionally send any command until I have received and processed the previous one.

My question is: Astream_NewData presumably interrupts whatever else is going on. Does it run at the end of the running Sub, or at the end of the running program command line? Or at some other point?
 

lip

Active Member
Licensed User
Longtime User
No.
The background thread reads the data and then sends it to the main thread message queue. Only when the main thread is free to process the message queue, the event will be raised.

Make sure to test it in release mode.

I've put a ToastMessage into Main_ActivityCreate (when FirstTime = False) and this pops up occasionally whilst commands are running. Does this mean there is definitely a problem? I have replaced all references to Main. with Starter. to avoid other activities using Process Globals in Main when it has stopped.
 
Upvote 0
Top