C# - 线程Join联接

C# - 线程Join联接 首页 / C#入门教程 / C# - 线程Join联接

它会导致所有调用线程等待,直到当前线程(联接的线程)终止或完成其任务。

using System;  
using System.Threading;  
public class MyThread  
{  
    public void Thread1()  
    {  
        for (int i = 0; i < 5; i++)  
        {  
            Console.WriteLine(i);  
            Thread.Sleep(200);  
        }  
    }  
}  
public class ThreadExample  
{  
    public static void Main()  
    {  
        MyThread mt = new MyThread();  
        Thread t1 = new Thread(new ThreadStart(mt.Thread1));  
        Thread t2 = new Thread(new ThreadStart(mt.Thread1));  
        Thread t3 = new Thread(new ThreadStart(mt.Thread1));  
        t1.Start();  
        t1.Join();  
        t2.Start();  
        t3.Start();  
    }  
}  

输出:

链接:https://www.learnfk.comhttps://www.learnfk.com/csharp/c-sharp-thread-join.html

来源:LearnFk无涯教程网

0
1
2
3
4
0
0
1
1
2
2
3
3
4
4

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

邱岳的产品手记 -〔邱岳〕

微服务架构核心20讲 -〔杨波〕

重学前端 -〔程劭非(winter)〕

DDD实战课 -〔欧创新〕

.NET Core开发实战 -〔肖伟宇〕

张汉东的Rust实战课 -〔张汉东〕

说透数字化转型 -〔付晓岩〕

Spring Cloud 微服务项目实战 -〔姚秋辰(姚半仙)〕

手把手带你搭建推荐系统 -〔黄鸿波〕

好记忆不如烂笔头。留下您的足迹吧 :)