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 | |
---|
1 | using System;
|
---|
2 | using System.Collections.Concurrent;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Text;
|
---|
6 | using System.Threading.Tasks;
|
---|
7 |
|
---|
8 | namespace 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.