Show / Hide Table of Contents

Class AsyncQueue<TItem>

Async queue that can be processed by an implementation of AsyncQueueProcessor<TItem>

Inheritance
object
AsyncQueueBase<TItem>
AsyncQueue<TItem>
Implements
IAsyncQueue<TItem>
IAsyncQueueBase<TItem>
Inherited Members
AsyncQueueBase<TItem>._itemsBeingProcessed
AsyncQueueBase<TItem>._dequeueLock
AsyncQueueBase<TItem>._principalAccessor
AsyncQueueBase<TItem>._logger
AsyncQueueBase<TItem>._endOfProcessingCancellation
AsyncQueueBase<TItem>.Enqueue(TItem)
AsyncQueueBase<TItem>.Requeue(IAsyncQueueProcessItemContext<TItem>)
AsyncQueueBase<TItem>.ProcessItemsAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken)
AsyncQueueBase<TItem>.SignalProcessingCanceled()
AsyncQueueBase<TItem>.WaitForItemsInQueueToBeProcessedAsync(CancellationToken)
AsyncQueueBase<TItem>.EnterQueueItemContext(AsyncQueueBase<TItem>.AsyncQueueItem)
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: SuperOffice.Threading
Assembly: SoCore.dll
Syntax
public class AsyncQueue<TItem> : AsyncQueueBase<TItem>, IAsyncQueue<TItem>, IAsyncQueueBase<TItem>
Type Parameters
Name Description
TItem

Item to add and process in the queue

Remarks

Get instance of the queue using ClassFactory or DI. ClassFactory.CreateRequired<IAsyncQueue<TItem>>()
This class contains both a queue and a mechanism to process items in the queue. Processing is done by calling the ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method, for instance from a BackgroundService that uses AsyncQueueProcessor<TQueue, TItem> as its base class. Our own AsyncQueueBase<TItem> class contains the ProcessItemsAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method (note plural form of Items in its name!). This is the method that contains the loop, which repeatedly calls our ProcessNextItemAsync method. This loop should only terminate throught the CancellationToken it was set up with.

Constructors

AsyncQueue(INSPrincipalAccessor, ILogger<AsyncQueue<TItem>>)

Async queue that can be processed by an implementation of AsyncQueueProcessor<TItem>

Declaration
public AsyncQueue(INSPrincipalAccessor principalAccessor, ILogger<AsyncQueue<TItem>> logger)
Parameters
Type Name Description
INSPrincipalAccessor principalAccessor
ILogger<AsyncQueue<TItem>> logger
Remarks

Get instance of the queue using ClassFactory or DI. ClassFactory.CreateRequired<IAsyncQueue<TItem>>()
This class contains both a queue and a mechanism to process items in the queue. Processing is done by calling the ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method, for instance from a BackgroundService that uses AsyncQueueProcessor<TQueue, TItem> as its base class. Our own AsyncQueueBase<TItem> class contains the ProcessItemsAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method (note plural form of Items in its name!). This is the method that contains the loop, which repeatedly calls our ProcessNextItemAsync method. This loop should only terminate throught the CancellationToken it was set up with.

Properties

HasItemsInTheQueue

True if there are items in the queue

Declaration
public override bool HasItemsInTheQueue { get; }
Property Value
Type Description
bool
Overrides
AsyncQueueBase<TItem>.HasItemsInTheQueue
Remarks

Get instance of the queue using ClassFactory or DI. ClassFactory.CreateRequired<IAsyncQueue<TItem>>()
This class contains both a queue and a mechanism to process items in the queue. Processing is done by calling the ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method, for instance from a BackgroundService that uses AsyncQueueProcessor<TQueue, TItem> as its base class. Our own AsyncQueueBase<TItem> class contains the ProcessItemsAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method (note plural form of Items in its name!). This is the method that contains the loop, which repeatedly calls our ProcessNextItemAsync method. This loop should only terminate throught the CancellationToken it was set up with.

Methods

GetInnerQueueCompletionTasks()

Async queue that can be processed by an implementation of AsyncQueueProcessor<TItem>

Declaration
protected override IEnumerable<Task> GetInnerQueueCompletionTasks()
Returns
Type Description
IEnumerable<Task>
Overrides
AsyncQueueBase<TItem>.GetInnerQueueCompletionTasks()
Remarks

Get instance of the queue using ClassFactory or DI. ClassFactory.CreateRequired<IAsyncQueue<TItem>>()
This class contains both a queue and a mechanism to process items in the queue. Processing is done by calling the ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method, for instance from a BackgroundService that uses AsyncQueueProcessor<TQueue, TItem> as its base class. Our own AsyncQueueBase<TItem> class contains the ProcessItemsAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method (note plural form of Items in its name!). This is the method that contains the loop, which repeatedly calls our ProcessNextItemAsync method. This loop should only terminate throught the CancellationToken it was set up with.

InnerEnqueue(AsyncQueueItem)

Async queue that can be processed by an implementation of AsyncQueueProcessor<TItem>

Declaration
protected override void InnerEnqueue(AsyncQueueBase<TItem>.AsyncQueueItem queItem)
Parameters
Type Name Description
AsyncQueueBase<TItem>.AsyncQueueItem queItem
Overrides
AsyncQueueBase<TItem>.InnerEnqueue(AsyncQueueBase<TItem>.AsyncQueueItem)
Remarks

Get instance of the queue using ClassFactory or DI. ClassFactory.CreateRequired<IAsyncQueue<TItem>>()
This class contains both a queue and a mechanism to process items in the queue. Processing is done by calling the ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method, for instance from a BackgroundService that uses AsyncQueueProcessor<TQueue, TItem> as its base class. Our own AsyncQueueBase<TItem> class contains the ProcessItemsAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method (note plural form of Items in its name!). This is the method that contains the loop, which repeatedly calls our ProcessNextItemAsync method. This loop should only terminate throught the CancellationToken it was set up with.

ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken)

Block until an item can be picked off the queue, or the cancellation token is signaled. Pick the top item off the queue and call the processor delegate.
Multiple calls (from separate Tasks) to this method are supported and will run in parallel if there are multiple items in the queue.

Declaration
public override Task ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem> processor, CancellationToken cancellationToken)
Parameters
Type Name Description
AsyncQueueProcessItemAsync<TItem> processor

The concrete method to be called for an item, when an item becomes available

CancellationToken cancellationToken
Returns
Type Description
Task
Overrides
AsyncQueueBase<TItem>.ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken)
Remarks

This method contains the mechanisms needed to safely pick items off the queue, or block until an item is available (in an async-friendly manner).
_itemsBeingProcessed contains the currently processing items. This is for information only.

ToArray(bool)

Get a snapshot of all the items in the queue

Declaration
public override TItem[] ToArray(bool includeItemsBeingProcessed)
Parameters
Type Name Description
bool includeItemsBeingProcessed

Include items currently being processed in the snapshot

Returns
Type Description
TItem[]
Overrides
AsyncQueueBase<TItem>.ToArray(bool)
Remarks

Get instance of the queue using ClassFactory or DI. ClassFactory.CreateRequired<IAsyncQueue<TItem>>()
This class contains both a queue and a mechanism to process items in the queue. Processing is done by calling the ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method, for instance from a BackgroundService that uses AsyncQueueProcessor<TQueue, TItem> as its base class. Our own AsyncQueueBase<TItem> class contains the ProcessItemsAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method (note plural form of Items in its name!). This is the method that contains the loop, which repeatedly calls our ProcessNextItemAsync method. This loop should only terminate throught the CancellationToken it was set up with.

Implements

IAsyncQueue<TItem>
IAsyncQueueBase<TItem>

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top