首页 > 编程语言 > 详细

C#等待子线程执行完毕

时间:2020-05-02 19:32:50      阅读:220      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsloeApp1
{

    class Program
    {
        static ManualResetEvent manualRestEventA = new ManualResetEvent(false);
        static ManualResetEvent manualRestEventB = new ManualResetEvent(false);
        static void Main(string[] args)
        {


            Task taskA = new Task(new Action(() => {
                for (int i = 0; i < 100; i++)
                {
                    Console.WriteLine("*******************************************************************");

                }
                manualRestEventA.Set();
            }));

            Task taskB = new Task(new Action(() => {
                for (int i = 0; i < 1000; i++)
                {
                    Console.WriteLine("____________________________________________________________________");
                }

                manualRestEventB.Set();
            }));

            taskA.Start();
            taskB.Start();

            manualRestEventA.WaitOne();
            manualRestEventB.WaitOne();

            Console.WriteLine("Synchornolyze Done");

            Console.ReadKey();
        }
    }
}

  

C#等待子线程执行完毕

原文:https://www.cnblogs.com/sclu/p/12818884.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!