H headingwest Member Licensed User Longtime User Sep 18, 2013 #1 Help. When I use AsyncStreams as in the BT tutorial, I get a problem if there's any delays in processing the buffer. I process here: Code: Copy Sub AStream_NewData (Buffer() As Byte) sMsgBuild = sMsgBuild & BytesToString(Buffer, 0, Buffer.Length, "UTF8") If sMsgBuild.EndsWith(CRLF) Then ProcessMessage(sMsgBuild) '<<---Jumps out of sub = problem. sMsgBuild = "" End If End Sub When it jumps out to ProcessMessage I use a dialog box. While I use the dialog box more messages are arriving in AStream_NewData which end up corrupted. This is in debug or release mode. If I remove the dialog box it works fine. I can also replicate this by putting a debug breakpoint in AStream_NewData. I end up again with corrupted data. Removing the breakpoint fixes it. This is bad as it appears that AStream_NewData can't really run asyncronously.? Or am I doing something wrong?
Help. When I use AsyncStreams as in the BT tutorial, I get a problem if there's any delays in processing the buffer. I process here: Code: Copy Sub AStream_NewData (Buffer() As Byte) sMsgBuild = sMsgBuild & BytesToString(Buffer, 0, Buffer.Length, "UTF8") If sMsgBuild.EndsWith(CRLF) Then ProcessMessage(sMsgBuild) '<<---Jumps out of sub = problem. sMsgBuild = "" End If End Sub When it jumps out to ProcessMessage I use a dialog box. While I use the dialog box more messages are arriving in AStream_NewData which end up corrupted. This is in debug or release mode. If I remove the dialog box it works fine. I can also replicate this by putting a debug breakpoint in AStream_NewData. I end up again with corrupted data. Removing the breakpoint fixes it. This is bad as it appears that AStream_NewData can't really run asyncronously.? Or am I doing something wrong?
Erel B4X founder Staff member Licensed User Longtime User Sep 18, 2013 #2 You should not show a modal dialog when working with AsyncStreams. The events will be queued in the message queue and will not be processed. The order of messages may also change. Upvote 0
You should not show a modal dialog when working with AsyncStreams. The events will be queued in the message queue and will not be processed. The order of messages may also change.
H headingwest Member Licensed User Longtime User Sep 18, 2013 #3 I am getting the order changed, and if I try hard enough some corrupted data. So no modal dialogs? Can I put the BT and AsyncStreams into a service or will that process and thread also get blocked by a modal dialog? Upvote 0
I am getting the order changed, and if I try hard enough some corrupted data. So no modal dialogs? Can I put the BT and AsyncStreams into a service or will that process and thread also get blocked by a modal dialog?
Erel B4X founder Staff member Licensed User Longtime User Sep 18, 2013 #4 It will not help. You should not show a modal dialog when working with AsyncStreams. Though I recommend you to move the communication code to a Service. Services are not paused like activities and are simpler to work with. Upvote 0
It will not help. You should not show a modal dialog when working with AsyncStreams. Though I recommend you to move the communication code to a Service. Services are not paused like activities and are simpler to work with.