using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplication1
{
class Product:IDisposable
{
EventWaitHandle EV = new AutoResetEvent(false);
object ob = new object();
Queue<string> ppe=new Queue<string>();
Thread t;
public Product()
{
t = new Thread(new ThreadStart(work));
t.Start();
}
public void SetIn(string ls)
{
ppe.Enqueue(ls);
EV.Set();
}
public void Dispose()
{
SetIn(null);
t.Join();
EV.Close();
}
public void work()
{
while (true)
{
string talk = null;
lock (ob)
if (ppe.Count > 0)
{
talk = ppe.Deque
c# 多线程 生产者/消费者队列 源码
最新推荐文章于 2023-02-22 18:35:49 发布