Table of Contents

Class BaseBlockingQueue<T, TF>

Namespace
Ecng.Collections
Assembly
Ecng.Collections.dll

Abstract base class for a blocking queue implementation with a generic type and an inner collection.

public abstract class BaseBlockingQueue<T, TF> : ISynchronizedCollection<T>, ISynchronizedCollection, ICollection<T>, IEnumerable<T>, IEnumerable, IBlockingQueue<T> where TF : ICollection<T>

Type Parameters

T

The type of elements in the queue.

TF

The type of the inner collection, which must implement ICollection<T>.

Inheritance
BaseBlockingQueue<T, TF>
Implements
Derived
Inherited Members
Extension Methods

Constructors

BaseBlockingQueue(TF)

Abstract base class for a blocking queue implementation with a generic type and an inner collection.

protected BaseBlockingQueue(TF innerCollection)

Parameters

innerCollection TF

Properties

Count

Gets the current number of items in the queue.

public int Count { get; }

Property Value

int

InnerCollection

Gets the inner collection used to store the queue elements.

protected TF InnerCollection { get; }

Property Value

TF

IsClosed

Gets a value indicating whether the queue is closed.

public bool IsClosed { get; }

Property Value

bool

MaxSize

Gets or sets the maximum size of the queue. A value of -1 indicates no size limit.

public int MaxSize { get; set; }

Property Value

int

Exceptions

ArgumentOutOfRangeException

Thrown when the value is 0 or less than -1.

SyncRoot

Gets the synchronization object used to coordinate access to the queue.

public SyncObject SyncRoot { get; }

Property Value

SyncObject

Methods

Clear()

Removes all items from the queue and notifies blocked threads.

public void Clear()

Close()

Closes the queue, preventing further enqueues and waking up any blocked threads.

public void Close()

Dequeue()

Removes and returns the item at the head of the queue.

public T Dequeue()

Returns

T

The dequeued item.

Enqueue(T, bool)

Adds an item to the queue, optionally forcing the enqueue even if the queue is full.

public void Enqueue(T item, bool force = false)

Parameters

item T

The item to add to the queue.

force bool

If true, adds the item regardless of the maximum size; otherwise, waits if the queue is full.

GetEnumerator()

Returns an enumerator that iterates through the queue.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

An enumerator for the queue.

OnDequeue()

Performs the actual dequeue operation on the inner collection.

protected abstract T OnDequeue()

Returns

T

The dequeued item.

OnEnqueue(T, bool)

Performs the actual enqueue operation on the inner collection.

protected abstract void OnEnqueue(T item, bool force)

Parameters

item T

The item to enqueue.

force bool

Indicates whether the enqueue is forced.

OnPeek()

Retrieves, but does not remove, the head of the queue.

protected abstract T OnPeek()

Returns

T

The item at the head of the queue.

Open()

Reopens the queue, allowing enqueue operations to proceed.

public void Open()

Peek()

Retrieves, but does not remove, the item at the head of the queue.

public T Peek()

Returns

T

The item at the head of the queue.

TryDequeue(out T, bool, bool)

Attempts to remove and return the item at the head of the queue.

public bool TryDequeue(out T value, bool exitOnClose = true, bool block = true)

Parameters

value T

When this method returns, contains the dequeued item if successful; otherwise, the default value.

exitOnClose bool

If true, exits if the queue is closed.

block bool

If true, blocks until an item is available; otherwise, returns immediately.

Returns

bool

True if an item was dequeued; otherwise, false.

TryPeek(out T, bool, bool)

Attempts to retrieve, but not remove, the item at the head of the queue.

public bool TryPeek(out T value, bool exitOnClose = true, bool block = true)

Parameters

value T

When this method returns, contains the peeked item if successful; otherwise, the default value.

exitOnClose bool

If true, exits if the queue is closed.

block bool

If true, blocks until an item is available; otherwise, returns immediately.

Returns

bool

True if an item was peeked; otherwise, false.

WaitUntilEmpty()

Blocks the current thread until the queue is empty or closed.

public void WaitUntilEmpty()