Show / Hide Table of Contents

Class Worker

Encapsulates a System.Threading.Thread running in the background, executing tasks from a TaskQueue.

Inheritance
System.Object
Worker
Implements
System.IDisposable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Moth.Tasks
Assembly: Moth.Tasks.dll
Syntax
public class Worker : IDisposable
Remarks

This class is thread-safe.

Constructors

| Improve this Doc View Source

Worker(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

The TaskQueue that the Worker will execute tasks from.

System.Boolean disposeTaskQueue

Determines whether the TaskQueue supplied with taskQueue is disposed when Dispose() is called.

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

taskQueue cannot be null.

| Improve this Doc View Source

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

The TaskQueue that the Worker will execute tasks from.

System.Boolean disposeTaskQueue

Determines whether the TaskQueue supplied with taskQueue is disposed when Dispose() is called.

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

taskQueue cannot be null.

Properties

| Improve this Doc View Source

IsRunning

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.

| Improve this Doc View Source

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 Source

Dispose()

Sends a signal to shutdown the thread. Also disposes of Tasks if specified in Worker constructor.

Declaration
public void Dispose()
| Improve this Doc View Source

Dispose(Boolean)

Sends a signal to shutdown the thread. Also disposes of Tasks if specified in Worker constructor.

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
System.Boolean disposing

true if called from Dispose(), false if called from finalizer.

| Improve this Doc View Source

Finalize()

Finalizes an instance of the Worker class.

Declaration
protected void Finalize()

Implements

System.IDisposable
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX