using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DistributedGA.Core.Util { public class SizedConcurrentQueue : ConcurrentQueue { public int Limit { get; set; } private readonly object syncObject = new object(); public new void Enqueue(T item) { base.Enqueue(item); lock (syncObject) { T overflow; while (base.Count > Limit) { base.TryDequeue(out overflow); } } } } }