线程加入
程序员文章站
2022-03-05 16:54:30
...
public final void join()
using System;
using System.Windows.Forms;
using System.Threading;
namespace Demo1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
}
Thread t1, t2;//全局变量
void Pro1()
{
int count = 0;
while (true)
{
progressBar1.PerformStep();//进度条按已设置的步长运行
Thread.Sleep(100);
count += progressBar1.Step;//统计进度
if (count==20)//到20%时,线程2加入
{
t2.Join();
}
}
}
void Pro2()
{
int count = 0;
while (true)
{
progressBar2.PerformStep();
Thread.Sleep(100);
count += progressBar1.Step;
if (count==100)
{
break;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
t1 = new Thread(Pro1);
t1.Start();
t2 = new Thread(Pro2);
t2.Start();
}
}
}
上一篇: 卡尔曼滤波
下一篇: python线程池应用场景-爬虫