Class FixedSizeConcurrentQueue<T>
- Namespace
- BSGameLib.Server.Collections
- Assembly
- BSGameLib.Server.dll
A thread-safe queue that keeps at most Size items. Enqueueing when it is full drops the oldest item.
public sealed class FixedSizeConcurrentQueue<T> : IProducerConsumerCollection<T>, ICollection, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
T
- Inheritance
-
FixedSizeConcurrentQueue<T>
- Implements
-
IEnumerable<T>
- Inherited Members
Constructors
FixedSizeConcurrentQueue(int)
Creates a queue that keeps at most size items.
public FixedSizeConcurrentQueue(int size)
Parameters
sizeint
Exceptions
- ArgumentOutOfRangeException
sizeis negative.
Properties
Count
The number of items in the queue.
public int Count { get; }
Property Value
IsSynchronized
Always false: the queue is thread-safe through its own methods, not a sync root.
public bool IsSynchronized { get; }
Property Value
Size
The most items the queue keeps.
public int Size { get; }
Property Value
SyncRoot
Not supported: throws NotSupportedException.
public object SyncRoot { get; }
Property Value
Methods
CopyTo(T[], int)
Copies the items, oldest first, into array from index.
public void CopyTo(T[] array, int index)
Parameters
arrayT[]indexint
Enqueue(T)
Adds item as the newest item, dropping the oldest items to keep
Size.
public void Enqueue(T item)
Parameters
itemT
GetEnumerator()
Enumerates a snapshot of the items, oldest first.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
ToArray()
Returns the items as an array, oldest first.
public T[] ToArray()
Returns
- T[]
TryDequeue(out T)
Removes the oldest item and returns it. Returns false when the queue is empty.
public bool TryDequeue(out T item)
Parameters
itemT
Returns
TryPeek(out T)
Returns the oldest item without removing it. Returns false when the queue is empty.
public bool TryPeek(out T item)
Parameters
itemT