VS VB.NET 多线程之插入线程

'在窗体中添加进度条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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值