Free cookie consent management tool by TermsFeed Policy Generator

source: branches/thasling/DistributedGA/DistributedGA.Core/Util/SizedConcurrentQueue.cs @ 13971

Last change on this file since 13971 was 13937, checked in by thasling, 8 years ago

#2615:
implemented ConcurrentQueue
made minor changes in Dispose-methods

File size: 587 bytes
Line 
1using System;
2using System.Collections.Concurrent;
3using System.Collections.Generic;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
8namespace DistributedGA.Core.Util {
9  public class SizedConcurrentQueue<T> : ConcurrentQueue<T> {
10    public int Limit { get; set; }
11    private readonly object syncObject = new object();
12
13    public new void Enqueue(T item) {
14      base.Enqueue(item);
15      lock (syncObject) {
16        T overflow;
17        while (base.Count > Limit) {
18          base.TryDequeue(out overflow);
19        }
20      }
21    }
22  }
23}
Note: See TracBrowser for help on using the repository browser.