首页 > 其他 > 详细

ManualResetEvent实现生产者消费者模式

时间:2015-06-28 17:32:27      阅读:158      评论:0      收藏:0      [点我收藏+]
  public class MreTest1
        {
            public static ManualResetEvent mre = new ManualResetEvent(false);

            public static void Add()
            {

                while (true)
                {
                    Thread.Sleep(1000);
                    Console.WriteLine(Thread.CurrentThread.Name + "\t生产者");
                    MreTest2.mre.Set();

                    mre.Reset();                    
                    mre.WaitOne();
                 
                }

            }
        }

        public class MreTest2
        {
            public static ManualResetEvent mre = new ManualResetEvent(false);
            public static void Del()
            {
                mre.WaitOne();
                while (true)
                {
                    Thread.Sleep(2000);
                    Console.WriteLine(Thread.CurrentThread.Name + "\t消费者");
                    MreTest1.mre.Set();

                    mre.Reset();                    
                    mre.WaitOne();                

                }

            }

        }

 

ManualResetEvent实现生产者消费者模式

原文:http://www.cnblogs.com/tgdjw/p/4605808.html

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