Class AsyncQueueHandler<TAsynchronousHandlerProcessor, TAsynchronousArgument>
Base class replacing legacy system for quing things into an IAsyncQueue<TItem>.
Inheritance
Inherited Members
Namespace: SuperOffice.Threading
Assembly: SoCore.dll
Syntax
public abstract class AsyncQueueHandler<TAsynchronousHandlerProcessor, TAsynchronousArgument> where TAsynchronousHandlerProcessor : AsynchronousHandlerProcessor<TAsynchronousArgument>, new() where TAsynchronousArgument : class
Type Parameters
| Name | Description |
|---|---|
| TAsynchronousHandlerProcessor | |
| TAsynchronousArgument |
Remarks
The Queue is processed by an instance of a hosted service, typically implementing AsyncQueueHandlerProcessor
Constructors
AsyncQueueHandler(IAsyncQueue<TAsynchronousHandlerProcessor>)
Default constructor
Declaration
protected AsyncQueueHandler(IAsyncQueue<TAsynchronousHandlerProcessor> queue)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncQueue<TAsynchronousHandlerProcessor> | queue | Queue instance typically obtained from DI |
Remarks
The Queue is processed by an instance of a hosted service, typically implementing AsyncQueueHandlerProcessor
Fields
_processor
Base class replacing legacy system for quing things into an IAsyncQueue<TItem>.
Declaration
protected readonly TAsynchronousHandlerProcessor _processor
Field Value
| Type | Description |
|---|---|
| TAsynchronousHandlerProcessor |
Remarks
The Queue is processed by an instance of a hosted service, typically implementing AsyncQueueHandlerProcessor
_queue
Internal (singleton) queue of processor instances that should be processed
Declaration
protected readonly IAsyncQueue<TAsynchronousHandlerProcessor> _queue
Field Value
| Type | Description |
|---|---|
| IAsyncQueue<TAsynchronousHandlerProcessor> |
Remarks
The Queue is processed by an instance of a hosted service, typically implementing AsyncQueueHandlerProcessor
Properties
HasWorkToDo
A flag property that reflects the output of SynchronousSetup(TAsynchronousArgument). It is true if there is work to do for the AsynchronousOperation().
Declaration
public bool HasWorkToDo { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
The Queue is processed by an instance of a hosted service, typically implementing AsyncQueueHandlerProcessor
Processor
Processor executing the operation.
Declaration
protected TAsynchronousHandlerProcessor Processor { get; }
Property Value
| Type | Description |
|---|---|
| TAsynchronousHandlerProcessor |
Remarks
The Queue is processed by an instance of a hosted service, typically implementing AsyncQueueHandlerProcessor
Methods
AsynchronousOperation()
Public interface for the asynchronous part of the operation. Any data needed for its execution has to be copied by the SynchronousSetup(TAsynchronousArgument), because you DO NOT KNOW when the OnOperation method will actually be called.
Declaration
public void AsynchronousOperation()
Remarks
You should not really call this method if the SynchronousSetup(TAsynchronousArgument) returned false, which can be checked by accessing the WorkToDo property. However, it is not an error to call this method anyway, as it will check the workToDo variable before actually doing anything.
However, if you forget to call SynchronousSetup(TAsynchronousArgument), you will get an exception here.Examples
AsynchronousHandler someOperation = new SomeOperation();
someOperation.SynchronousSetup( currentQuery );
...
if( someOperation.WorkToDo )
someOperation.AsynchronousOperation();
// we're done, async thread will sooner or later do the work
OnSetup(TAsynchronousArgument)
Derived classes that need other behaviour than simply copying the ArgumentParameterCollection and PrimaryKey information from the incoming query should override this method.
Declaration
protected virtual bool OnSetup(TAsynchronousArgument inputQuery)
Parameters
| Type | Name | Description |
|---|---|---|
| TAsynchronousArgument | inputQuery | Incoming query to be copied |
Returns
| Type | Description |
|---|---|
| bool | true - this default implementation signals that there IS something to do in the main routine |
Remarks
The Queue is processed by an instance of a hosted service, typically implementing AsyncQueueHandlerProcessor
SynchronousSetup(TAsynchronousArgument)
Public interface for the synchronous part of the operation. The query to be processed must be a parameter to this operation.
Declaration
public bool SynchronousSetup(TAsynchronousArgument inputQuery)
Parameters
| Type | Name | Description |
|---|---|---|
| TAsynchronousArgument | inputQuery | Query to be processed by the actual service |
Returns
| Type | Description |
|---|---|
| bool | TRUE if there is something to do, i.e., if AsynchronousOperation should be called |
Remarks
The Queue is processed by an instance of a hosted service, typically implementing AsyncQueueHandlerProcessor