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:
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?