Table of Contents

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
Inherited Members

Constructors

FixedSizeConcurrentQueue(int)

Creates a queue that keeps at most size items.

public FixedSizeConcurrentQueue(int size)

Parameters

size int

Exceptions

ArgumentOutOfRangeException

size is negative.

Properties

Count

The number of items in the queue.

public int Count { get; }

Property Value

int

IsSynchronized

Always false: the queue is thread-safe through its own methods, not a sync root.

public bool IsSynchronized { get; }

Property Value

bool

Size

The most items the queue keeps.

public int Size { get; }

Property Value

int

SyncRoot

Not supported: throws NotSupportedException.

public object SyncRoot { get; }

Property Value

object

Methods

CopyTo(T[], int)

Copies the items, oldest first, into array from index.

public void CopyTo(T[] array, int index)

Parameters

array T[]
index int

Enqueue(T)

Adds item as the newest item, dropping the oldest items to keep Size.

public void Enqueue(T item)

Parameters

item T

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

item T

Returns

bool

TryPeek(out T)

Returns the oldest item without removing it. Returns false when the queue is empty.

public bool TryPeek(out T item)

Parameters

item T

Returns

bool