16,550
社区成员
发帖
与我相关
我的任务
分享
Imports System.Threading
Imports System.Windows.Forms
Public Class Form1
Dim t As Thread
Public Delegate Sub SetText1(ByVal [text] As String)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
t = New Thread(New ThreadStart(AddressOf Me.SetText1))
t.Start()
End Sub
Public Sub SetText1(ByVal [text] As String)
' InvokeRequired required compares the thread ID of the
' calling thread to the thread ID of the creating thread.
' If these threads are different, it returns true.
If Me.TextBox1.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[text]})
Else
Me.TextBox1.Text = [text]
End If
End Sub
End Class