I am reading bytes from a serial port and storing them in an array. I would then like to display the array contents to a textbox. I keep getting this error code --> "Cross-thread operation not valid. Control TextBox1 accessed from a thread other than the one it was created on". My code is below. what am I doing wrong?
Thanks
Thanks
VB.NET:
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
While SerialPort1.BytesToRead And SerialPort1.IsOpen
If SerialPort1.IsOpen Then
AccelRaw = SerialPort1.ReadByte()
End If
If (Not oFileStream Is Nothing) Then
If (oFileStream.CanWrite = True) Then
oFileStream.WriteByte(AccelRaw)
End If
End If
Me.TextBox1.Text = AccelRaw
ByteArray(BuffIndex) = AccelRaw
BuffIndex = (BuffIndex + 1) Mod Buffsize
End While
End Sub