在类模块中,做串口通讯,但是在返回值时,提示“跨线程操作”,
在类模块中,做串口通讯,但是在返回值时,提示“跨线程操作”,
Event CommData(ByVal retValue As String)...... Private Sub Rs232_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles Rs232.DataReceived Try Dim Indata As String = String.Empty ' If Not CommState Then Exit Sub If e.EventType <> SerialData.Chars OrElse Not CommState Then Exit Sub Indata = Rs232.ReadExisting Console.WriteLine("返回值:" & Indata) RaiseEvent CommData(Indata) '这一行不知道采用什么样方式来处理,此数据返回到窗体TEXTBOX1.TEXT中 'Dim a As SeTextCallBack = AddressOf ShowStr 'a(Indata) Catch ex As Exception ' MsgBox(ex.Message & "Read Com error!") Throw New Exception(ex.Message & vbCrLf & "Read Com error!") End Try End Sub