Class Worker
Encapsulates a System.Threading.Thread running in the background, executing tasks from a TaskQueue.
Inheritance
Implements
Inherited Members
Namespace: Moth.Tasks
Assembly: Moth.Tasks.dll
Syntax
public class Worker : IDisposable
Remarks
This class is thread-safe.
Constructors
| Improve this Doc View SourceWorker(TaskQueue, Boolean, Boolean, IProfiler, EventHandler<TaskExceptionEventArgs>)
Initializes a new instance of the Worker class.
Declaration
public Worker(TaskQueue taskQueue, bool disposeTaskQueue, bool isBackground, IProfiler profiler = null, EventHandler<TaskExceptionEventArgs> exceptionEventHandler = null)
Parameters
Type | Name | Description |
---|---|---|
TaskQueue | taskQueue | |
System.Boolean | disposeTaskQueue | Determines whether the TaskQueue supplied with |
System.Boolean | isBackground | Defines the System.Threading.Thread.IsBackground property of the internal thread. |
IProfiler | profiler | IProfiler used to profile tasks. May be null. |
System.EventHandler<TaskExceptionEventArgs> | exceptionEventHandler | Method invoked if a task throws an exception. May be null. |
Remarks
The Worker will start executing tasks automatically.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Worker(TaskQueue, Boolean, Boolean, ProfilerProvider, EventHandler<TaskExceptionEventArgs>)
Initializes a new instance of the Worker class.
Declaration
public Worker(TaskQueue taskQueue, bool disposeTaskQueue, bool isBackground, ProfilerProvider profilerProvider, EventHandler<TaskExceptionEventArgs> exceptionEventHandler = null)
Parameters
Type | Name | Description |
---|---|---|
TaskQueue | taskQueue | |
System.Boolean | disposeTaskQueue | Determines whether the TaskQueue supplied with |
System.Boolean | isBackground | Defines the System.Threading.Thread.IsBackground property of the internal thread. |
ProfilerProvider | profilerProvider | A ProfilerProvider which may provide an IProfiler for the Worker. May be null. |
System.EventHandler<TaskExceptionEventArgs> | exceptionEventHandler | Method invoked if a task throws an exception. May be null. |
Remarks
The Worker will start executing tasks automatically.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
Properties
| Improve this Doc View SourceIsRunning
Gets a value indicating whether the thread is running.
Declaration
public bool IsRunning { get; protected set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
May be true for a short while even after Dispose() is called.
Tasks
The TaskQueue of which the worker is executing tasks from.
Declaration
public TaskQueue Tasks { get; }
Property Value
Type | Description |
---|---|
TaskQueue |
Methods
| Improve this Doc View SourceDispose()
Declaration
public void Dispose()
Dispose(Boolean)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | true if called from Dispose(), false if called from finalizer. |
Finalize()
Finalizes an instance of the Worker class.
Declaration
protected void Finalize()