Class ThreadWorkerBase
Provides a base implementation for application workers that perform continuous, long-running tasks. This class provides the ability to perform fine-grained control on these tasks.
Inherited Members
Namespace: Swan.Threading
Syntax
public abstract class ThreadWorkerBase : WorkerBase, IWorker, IDisposable
Constructors
ThreadWorkerBase(String, ThreadPriority, TimeSpan, IWorkerDelayProvider)
Initializes a new instance of the ThreadWorkerBase class.
Declaration
protected ThreadWorkerBase(string name, ThreadPriority priority, TimeSpan period, IWorkerDelayProvider delayProvider)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name. |
ThreadPriority | priority | The thread priority. |
TimeSpan | period | The interval of cycle execution. |
IWorkerDelayProvider | delayProvider | The cycle delay provide implementation. |
ThreadWorkerBase(String, TimeSpan)
Initializes a new instance of the ThreadWorkerBase class.
Declaration
protected ThreadWorkerBase(string name, TimeSpan period)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name. |
TimeSpan | period | The execution interval. |
Properties
DelayProvider
Provides an implementation on a cycle delay provider.
Declaration
protected IWorkerDelayProvider DelayProvider { get; }
Property Value
Type | Description |
---|---|
IWorkerDelayProvider |
Methods
ExecuteCycleDelay(Int32, Task, CancellationToken)
Suspends execution queues a new new cycle for execution. The delay is given in milliseconds. When overridden in a derived class the wait handle will be set whenever an interrupt is received.
Declaration
protected virtual void ExecuteCycleDelay(int wantedDelay, Task delayTask, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
Int32 | wantedDelay | The remaining delay to wait for in the cycle. |
Task | delayTask | Contains a reference to a task with the scheduled period delay. |
CancellationToken | token | The cancellation token to cancel waiting. |
OnDisposing()
This method is called automatically when Dispose() is called. Makes sure you release all resources within this call.
Declaration
protected override void OnDisposing()
Overrides
PauseAsync()
Declaration
public override Task<WorkerState> PauseAsync()
Returns
Type | Description |
---|---|
Task<WorkerState> |
Overrides
ResumeAsync()
Declaration
public override Task<WorkerState> ResumeAsync()
Returns
Type | Description |
---|---|
Task<WorkerState> |
Overrides
StartAsync()
Declaration
public override Task<WorkerState> StartAsync()
Returns
Type | Description |
---|---|
Task<WorkerState> |
Overrides
StopAsync()
Declaration
public override Task<WorkerState> StopAsync()
Returns
Type | Description |
---|---|
Task<WorkerState> |