Modified relevant code. This seems to be doing the right thing.
The .Read call does not block execution, which is necessary here, so a loop is still used, but the Thread.Sleep (250) before the application.doevents seems to prevent the CPU from getting monopolized by the busy loop.
Does this make sense?
vb.net Code:
If curLab.WaitForACKnowledgment Then tmrSend.Start() bElapsed = False sReply = "" If stream.CanRead Then Dim lenReply As Integer, iOffset As Integer, iSize As Integer iSize = 1024 Dim strReply(iSize) As Byte Do Until bElapsed Or lenReply > 0 Thread.Sleep(250) Application.DoEvents() lenReply = stream.Read(strReply, iOffset, iSize) sReply = sReply & ByteArrayToString(strReply) If lenReply > iSize Then iOffset = iOffset + lenReply ElseIf lenReply > 0 And lenReply <= iSize Then Exit Do End If Loop End If End If tmrSend.Stop() stream.Close(500) tcp.Close() bDataSent = True




Reply With Quote