Пример #1
0
    /// <summary>
    /// 生产者线程
    /// </summary>
    /// <param name="parameter"></param>
    void ProducerThread(object parameter)
    {
        // 拿到参数
        Parameter par = parameter as Parameter;

        // 拿到缓冲区
        QueueProduces produces = par.Produces;

        // 拿到生产者名字
        String producerName = par.Name;

        // 实例化生产者
        Producer producer = new Producer(producerName);

        // 打印日志
        StringBuilder log = new StringBuilder("Producer ");

        log.Append("Name: ").Append(producerName);
        Console.WriteLine(log);

        // 该生产者一直生产产品
        while (true)
        {
            Produce produce = Produce.Create(producerName, 1000, 2000);
            produces.Push(produce);
            Thread.Sleep(1000);
        }
    }