VB.net 与线程

前端之家收集整理的这篇文章主要介绍了VB.net 与线程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Imports@H_404_10@ System.Threading
Imports@H_404_10@ System


Public Class@H_404_10@ Form1
    Dim th1,th2 As@H_404_10@ Thread
    Public Sub@H_404_10@ Method1()
        Dim i As Integer
        For i = 1 To 100

            If Me.Label1.BackColor = Color.DarkRed Then
                Me.Label1.BackColor =@H_404_10@ Color.Gold
            End If@H_404_10@
            System.Threading.Thread.Sleep(100@H_404_10@)
            If Me.Label1.BackColor = Color.Gold Then
                Me.Label1.BackColor =@H_404_10@ Color.DarkRed
            End If@H_404_10@
            System.Threading.Thread.Sleep(100@H_404_10@)
        Next
         
    End Sub
    Public Sub@H_404_10@ Method2()
        Dim i As Integer
        For i = 1 To 100
            If Me.Label2.BackColor = Color.DarkRed Then
                Me.Label2.BackColor =@H_404_10@ Color.Gold
            End If@H_404_10@
            System.Threading.Thread.Sleep(500@H_404_10@)
            If Me.Label2.BackColor = Color.Gold Then
                Me.Label2.BackColor =@H_404_10@ Color.DarkRed
            End If@H_404_10@
            System.Threading.Thread.Sleep(500@H_404_10@)
        Next
    End Sub
    Private Sub Button1_Click(sender As Object,e As EventArgs) Handles@H_404_10@ Button1.Click
        Me.Label1.BackColor =@H_404_10@ Color.DarkRed
        Me.Label2.BackColor =@H_404_10@ Color.DarkRed


        th1 = New Thread(New ThreadStart(AddressOf@H_404_10@ Method1))
        th1.Start()

        th2 = New Thread(New ThreadStart(AddressOf@H_404_10@ Method2))
        th2.Start()
        System.Threading.Thread.Sleep(1000@H_404_10@)
    End Sub

    Private Sub Form1_Load(sender As Object,e As EventArgs) Handles Me@H_404_10@.FormClosed
        th1.Abort()  调用方法通常会终止线程。
@H_404_10@        th2.Abort()
    End Sub

End Class

猜你在找的VB相关文章