Imports System.Threading Public Class Form1 Private Sub BtnRunUpdate_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles BtnRunUpdate.Click Me.BtnRunUpdate.Text = "执行..." Dim t As Thread = New Thread(New ThreadStart(AddressOf RunDownLoadFile)) t.IsBackground = True t.Name = "RunDownLoadFile" t.Start() End Sub Private Sub RunDownLoadFile() For i = 0 To 50 SetTextBoxData(i) Thread.Sleep(100) Next ResetDownLoadBtn() End Sub Public Delegate Sub SetTextBoxCallBack(ByVal strText As String) Private Sub SetTextBoxData(ByVal strData As String) If Me.TxtBoxData.Invokerequired Then Dim callback As New SetTextBoxCallBack(AddressOf SetTextBoxData) Me.BeginInvoke(callback,New Object() {strData}) Else Me.TxtBoxData.Text = strData End If End Sub Private Sub ResetDownLoadBtn() If Me.BtnRunUpdate.Invokerequired Then Dim mi As New MethodInvoker(AddressOf ResetDownLoadBtn) Me.BeginInvoke(mi) Else Me.BtnRunUpdate.Enabled = True Me.BtnRunUpdate.Text = "完成(&F)" Me.BtnRunUpdate.Select() End If End Sub Private Sub BtnReset_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles BtnReset.Click Me.BtnRunUpdate.Text = "重新开始" End Sub End Class
原始多线程例子,没采用lambda表达式。