//线程1 负责 enqueue
lock (_queProduction)
{
_queProduction.Enqueue(dt);
} //线程2 负责将_queProduction对象截断并赋值给queue,然后重新实例化_queProduction
Queue<DataTable> queue = null;
lock (_queProduction)
{
queue = _queProduction;
_queProduction = new Queue<DataTable>();
}描述 :要实现线程2 _queProduction 实例化新对象时,线程1 不 enqueue
怎么写~~~
其中提供有ConcurrentQueue<T>泛型类,还有BlockingCollection<T>等,应该可以实现你的要求。链接如下:http://msdn.microsoft.com/zh-cn/library/dd997305.aspx
lock (rLockqueProduction)
{
_queProduction.Enqueue(dt);
} //线程2 负责将_queProduction对象截断并赋值给queue,然后重新实例化_queProduction
Queue<DataTable> queue = null;
lock (rLockqueProduction)
{
queue = _queProduction;
_queProduction = new Queue<DataTable>();
}
这样就行了,