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
-
ICollection<T>IEnumerable<T>
- 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
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
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
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
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
TThe item to add to the queue.
force
boolIf 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
TThe item to enqueue.
force
boolIndicates 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
TWhen this method returns, contains the dequeued item if successful; otherwise, the default value.
exitOnClose
boolIf true, exits if the queue is closed.
block
boolIf 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
TWhen this method returns, contains the peeked item if successful; otherwise, the default value.
exitOnClose
boolIf true, exits if the queue is closed.
block
boolIf 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()