1234567891011121314151617181920212223242526272829303132 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Collections.Concurrent;
- namespace Aitex.DataAnalysis.Core
- {
- public class FixSizeQueue<T> : ConcurrentQueue<T>
- {
- public int FixedSize { get; private set; }
- public FixSizeQueue(int size)
- {
- FixedSize = size;
- }
- public new void Enqueue(T obj)
- {
- base.Enqueue(obj);
- lock (this)
- {
- while (base.Count > FixedSize)
- {
- T outObj;
- base.TryDequeue(out outObj);
- }
- }
- }
- }
- }
|