I have a problem with my code. The error is
Cross-thread operation not valid: control 'label1' accessed from a thread other than the thread it was created on
the code is
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.BaudRate = 9600
SerialPort1.PortName = "COM9"
Try
SerialPort1.Open()
Catch ex As Exception
End Try
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim data As String
data = SerialPort1.ReadLine()
Label1.Text = data
End Sub
End Class
How do I fix it?