VB.Net程序设计:原始多线程例子VS2008版

前端之家收集整理的这篇文章主要介绍了VB.Net程序设计:原始多线程例子VS2008版前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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表达式。

原文链接:https://www.f2er.com/vb/258271.html

猜你在找的VB相关文章