I tried a few changes like SyncLock and CanWrite but it is still having the same issue:
vb Code:
''' <summary> ''' Sends binary data. ''' </summary> Public Sub sendData(ByVal data() As Byte, Optional ByVal curStream As NetworkStream = Nothing) Try SyncLock curStream Dim endbytes() As Byte = System.Text.Encoding.ASCII.GetBytes("{682427e7-6a56-4513-87f1-2dec81ddae2d}") Dim lenBytes() As Byte = System.Text.Encoding.ASCII.GetBytes(data.Length) If curStream.CanWrite Then curStream.Write(lenBytes, 0, lenBytes.Length) '<----------- It is getting stuck here sometimes End If If curStream.CanWrite Then curStream.Write(endbytes, 0, endbytes.Length) '<----------- It is getting stuck here sometimes End If If curStream.CanWrite Then curStream.Write(data, 0, data.Length) End If curStream.Flush() End SyncLock Catch End Try 'If curStream IsNot Nothing Then ' curStream.Write(data, 0, data.Length) 'End If End Sub




Reply With Quote