16,554
社区成员
发帖
与我相关
我的任务
分享
Public Class Form1
Protected Delegate Sub dis(ByVal i As Integer)
Protected Sub dis_num(ByVal i As Integer)
Me.TextBox1.Text = i.ToString
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim th As New Threading.Thread(New Threading.ThreadStart(AddressOf td))
th.IsBackground = True
th.Start()
End Sub
Sub td()
Dim i As Integer
For i = 1 To 3
Dim p As New dis(AddressOf dis_num)
p.Invoke(i)
i = i + 1
Threading.Thread.Sleep(1000)
Next
End Sub
End Class
Imports System.Threading
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim th As New Thread(AddressOf MyThreadProc)
th.Start()
End Sub
Public Sub MyThreadProc()
'更新ui资源例子
Me.Invoke(New VoidDelegate(AddressOf UpdateText))
End Sub
Public Delegate Sub VoidDelegate()
Public Sub UpdateText()
Me.Text = "Modified by thread"
End Sub
End Class