首页 > 其他 > 详细

信号量 AutoResetEvent与WaitHandle.WaitAll使用。

时间:2017-07-22 20:26:36      阅读:467      评论:0      收藏:0      [点我收藏+]
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使用。

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

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