异步调用的问题....
自己写了一个收消息的类,里面通过事件把收到的消息返回显示到界面的txtOutput中.
显示
Cross-thread operation not valid: Control 'txtOutput ' accessed from a thread other than the thread it was created on.
以前的代码找不到了,感觉就是这样写的啊...为什么.......怎么办啊???
[解决办法]
跨线程访问对象在 2005 里面被当作异常抛出了
Delegate Sub SetTxtOutputCallback([text] As String)
Private Sub SetTxtOutput(ByVal [text] As String)
If Me.textBox1.InvokeRequired Then
Dim d As New SetTxtOutputCallback(AddressOf SetTxtOutput)
Me.Invoke(d, New Object() {[text]})
Else
Me.txtOutput.Text &= [text]
End If
End Sub
然后在你执行 Me.txtOutput.Text &= str 的地方修改为
SetTxtOutput(str)