Class ThreadedQueueProcessor<T>
Class which takes a worker and a queue, and automatically runs the worker in the background, but only queues on work-item at the time.
Namespace: SuperOffice.Util
Assembly: SoCore.dll
Syntax
public class ThreadedQueueProcessor<T> : Object
Type Parameters
Name | Description |
---|---|
T |
Constructors
ThreadedQueueProcessor(Action<T>, String, Int32)
Start a background thread to process items kept on a queue. Thread terminates when queue is empty.
Declaration
public ThreadedQueueProcessor(Action<T> OnWork, string workerThreadName = "ThreadedQueueProcessor-thread", int keepAliveSeconds = 0)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | OnWork | Method to call to process items. |
String | workerThreadName | Background thread name |
Int32 | keepAliveSeconds | Keep the thread alive X seconds to see if more work arrives before terminating. |
Properties
ItemsQueued
Total number of items processed by queue. For diagnostics and testing.
Declaration
public int ItemsQueued { get; }
Property Value
Type | Description |
---|---|
Int32 |
QueueLength
Number of items in queue. For diagnostics and testing.
Declaration
public int QueueLength { get; }
Property Value
Type | Description |
---|---|
Int32 |
ThreadsCreated
Total number of threads created to process work. For diagnostics.
Declaration
public int ThreadsCreated { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
AddWork(T)
Class which takes a worker and a queue, and automatically runs the worker in the background, but only queues on work-item at the time.
Declaration
public void AddWork(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item |
AwaitDisposedWorked()
Method used in testing to verify correctness.
Declaration
public void AwaitDisposedWorked()
AwaitEmptyQueue()
Method used in testing to verify correctness.
Declaration
public void AwaitEmptyQueue()
ToString()
Class which takes a worker and a queue, and automatically runs the worker in the background, but only queues on work-item at the time.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |