【线程嘱托】关于vb.net最简单的线程委托
【线程委托】关于vb.net最简单的线程委托[解决办法]线程里改控件值 this.Invoke((ThreadStart)delegate(){Th
【线程委托】关于vb.net最简单的线程委托
[解决办法]
线程里改控件值
this.Invoke((ThreadStart)delegate()
{
This.Text =sum.ToString();
});
[解决办法]将Me.Text = CStr(sum)改为Me.Invoke(Sub() Me.Text = CStr(sum))就行
[解决办法] Private Delegate Sub myDelegate(ByVal myString As String) '自定义一个委托
Private Sub SetWindowText(ByVal myString As String) '与委托相同签名的函数或过程
Me.Text = myString
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyThread As New System.Threading.Thread(AddressOf sum)
MyThread.Start()
End Sub
Private Sub sum()
Dim i, sum As Integer
For i = 0 To 100
sum += i
Next
Me.Invoke(New myDelegate(AddressOf SetWindowText), sum.ToString) '委托的调用
End Sub