我正在尝试将文本设置为标签Label_caller.Text = phone_number
,但出现了以下错误:"System.InvalidOperationException: 跨线程操作无效: 从创建它的线程以外的线程访问控件'Label_caller'。" 我该如何解决这个问题?我如何使用关键字Me.?
我正在尝试将文本设置为标签Label_caller.Text = phone_number
,但出现了以下错误:"System.InvalidOperationException: 跨线程操作无效: 从创建它的线程以外的线程访问控件'Label_caller'。" 我该如何解决这个问题?我如何使用关键字Me.?
Private Sub UpdateTextBox(ByVal phone_number As String)
If Me.InvokeRequired Then
Dim args() As String = {phone_number}
Me.Invoke(New Action(Of String)(AddressOf UpdateTextBox), args)
Return
End IF
Label_caller.Text = phone_number
End Sub
我可能回答得很晚,但在表单加载事件中添加以下代码似乎可以解决问题。
不确定这是否是完美的答案:
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False