生产者和消费者,是多线程中的经典问题,听过java方面的这个问题的培训,闲暇时用.net实现了这

   个问题。在此实现的是,生产一个消息后,消费一个消息,再生产一个消息,循环往复。

   1.消息代码 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProducerAndConsumer
{
    public class Info
    {
        private String name;

        public String Name
        {
            get { return name; }
            set { name = value; }
        }
        private String content;

        public String Content
        {
            get { return content; }
            set { content = value; }
        }

        private Boolean hasContent;

        public Boolean HasContent
        {
            get { return hasContent; }
            set { hasContent = value; }
        }
        private Object lockObj = new Object();

        public Object LockObj
        {
            get { return lockObj; }
        }

    }
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
  • 2021-08-09
  • 2021-08-20
猜你喜欢
  • 2021-11-30
  • 2022-12-23
  • 2021-12-05
  • 2021-11-30
  • 2021-11-30
  • 2021-10-03
相关资源
相似解决方案