'在窗体中添加进度条ProgressBar1 and ProgressBar2.编辑代码如下,实现进度条1运动到20%时运行进度条2然后再运行进度条1.
Imports System
Imports System.Threading '添加进程的命名空间
Public Class Form1
Dim t1 As Thread '定义线程
Dim t2 As Thread
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CheckForIllegalCrossThreadCalls = False '实现线程间调用窗体的控件-进度条
t1 = New Thread(New ThreadStart(AddressOf pro1)) '实例化线程的对象
t1.Start() '启动线程
t2 = New Thread(New ThreadStart(AddressOf pro2))
t2.Start()
End Sub
Sub pro1()
Dim count As Integer = 0
While (True)
ProgressBar1.PerformStep()
count += ProgressBar1.Step
Thread.Sleep(100)
If count = 20 Then
t2.Join() ' 插入线程
End If
End While
End Sub
Sub pro2()
Dim count As Integer = 0
While (True)
ProgressBar2.PerformStep()
count += ProgressBar2.Step
Thread.Sleep(100)
If count = 100 Then
Exit Sub
End If
End While
End Sub
End Class
VS VB.NET 多线程之插入线程
最新推荐文章于 2021-02-10 10:35:17 发布