Table of Contents

Interface IBlockingQueue<T>

Namespace
Ecng.Collections
Assembly
Ecng.Collections.dll

Represents a blocking queue interface for managing items in a thread-safe manner.

public interface IBlockingQueue<T>

Type Parameters

T

The type of elements in the queue.

Extension Methods

Properties

Count

Gets the number of elements contained in the queue.

int Count { get; }

Property Value

int

IsClosed

Gets a value indicating whether the queue is closed.

bool IsClosed { get; }

Property Value

bool

MaxSize

Gets or sets the maximum number of elements that the queue can hold.

int MaxSize { get; set; }

Property Value

int

Methods

Clear()

Removes all objects from the queue.

void Clear()

Close()

Closes the queue to prevent further enqueuing operations.

void Close()

Dequeue()

Removes and returns the object at the beginning of the queue.

T Dequeue()

Returns

T

The object that is removed from the beginning of the queue.

Enqueue(T, bool)

Adds an item to the end of the queue.

void Enqueue(T item, bool force = false)

Parameters

item T

The item to add.

force bool

If set to true, the item is enqueued even if the queue is at its maximum capacity.

Open()

Opens the queue, enabling enqueuing and dequeuing operations.

void Open()

Peek()

Returns the object at the beginning of the queue without removing it.

T Peek()

Returns

T

The object at the beginning of the queue.

TryDequeue(out T, bool, bool)

Attempts to remove and return the object at the beginning of the queue.

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

Parameters

value T

When this method returns, contains the object removed from the beginning of the queue, if the operation succeeded.

exitOnClose bool

If set to true, the operation exits if the queue is closed.

block bool

If set to true, blocks until an item is available.

Returns

bool

true if an object was successfully removed; otherwise, false.

TryPeek(out T, bool, bool)

Attempts to return the object at the beginning of the queue without removing it.

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

Parameters

value T

When this method returns, contains the object at the beginning of the queue, if the operation succeeded.

exitOnClose bool

If set to true, the operation exits if the queue is closed.

block bool

If set to true, blocks until an item is available.

Returns

bool

true if an object was successfully retrieved; otherwise, false.

WaitUntilEmpty()

Blocks the current thread until the queue becomes empty.

void WaitUntilEmpty()