我想限制 BlockingCollection 的大小。如果我想添加另一个项目并且集合已满,则必须删除最旧的项目。是否有特定于此任务的类或我的解决方案可以?
BlockingCollection<string> collection = new BlockingCollection<string>(10);
string newString = "";
//Not an elegant solution?
if (collection.Count == collection.BoundedCapacity)
{
string dummy;
collection.TryTake(out dummy);
}
collection.Add(newString);
EDIT1:类似的问题:ThreadSafe FIFO List with Automatic Size Limit Management