码迷,mamicode.com
首页 > 其他好文 > 详细

信号量 AutoResetEvent与WaitHandle.WaitAll使用。

时间:2017-07-22 20:58:09      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:nbsp   system   linq   ogr   main   back   div   sys   using   

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

using System.Threading.Tasks;

namespace ConsoleApplication11

{

    class Program

    {

     

        static void Main(string[] args)

        {

            AutoResetEvent[] AutoR = new AutoResetEvent[5];

            for (int i = 0; i < AutoR.Length; i++)

            {

                AutoR[i] = new AutoResetEvent(false);

                Thread td = new Thread(new ParameterizedThreadStart(ok));

                td.IsBackground = true;

                td.Start(AutoR[i]);

            }

            WaitHandle.WaitAll(AutoR);

            Console.WriteLine("全部收到信息,完成任务");

        }

        static void ok(object i)

        {

            AutoResetEvent reset = (AutoResetEvent)i;

            Console.WriteLine("程序往下执行。");

            Thread.Sleep(10000);

            reset.Set();//设置为有信号。

        }

    }
} 

 

信号量 AutoResetEvent与WaitHandle.WaitAll使用。

标签:nbsp   system   linq   ogr   main   back   div   sys   using   

原文地址:http://www.cnblogs.com/larva/p/7222341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!