Table of Contents

Interface IWorkerThread

Namespace
TCSystem.Thread
Assembly
TCSystem.Thread.dll

Represents a dedicated worker thread that executes queued actions in FIFO order.

public interface IWorkerThread

Properties

CancellationToken

Gets the token canceled when the worker is stopped.

CancellationToken CancellationToken { get; }

Property Value

CancellationToken

IsBusy

Gets whether an action is executing or queued.

bool IsBusy { get; }

Property Value

bool

NumOpenActions

Gets the number of actions waiting in the queue.

int NumOpenActions { get; }

Property Value

int

Methods

ClearOpenCommands()

Removes queued actions that have not started.

void ClearOpenCommands()

ClearOpenCommandsAsync()

Asynchronously acquires the queue lock and removes actions that have not started.

Task ClearOpenCommandsAsync()

Returns

Task

ExecuteCommand(Action)

Queues an action for execution.

void ExecuteCommand(Action action)

Parameters

action Action

ExecuteCommand(Action, string)

Queues an action with a message used when logging failures.

void ExecuteCommand(Action action, string message)

Parameters

action Action
message string

ExecuteCommandAsync(Action)

Asynchronously acquires the queue lock and queues an action.

Task ExecuteCommandAsync(Action action)

Parameters

action Action

Returns

Task

ExecuteCommandAsync(Action, string)

Asynchronously acquires the queue lock and queues an action with a diagnostic message.

Task ExecuteCommandAsync(Action action, string message)

Parameters

action Action
message string

Returns

Task

StopThread(TimeSpan?)

Stops the worker, clears pending actions, and waits for the thread to terminate.

void StopThread(TimeSpan? timeOut = null)

Parameters

timeOut TimeSpan?

Events

IdleEvent

Occurs when the worker enters or leaves the idle state; the argument is true when idle.

event Action<bool> IdleEvent

Event Type

Action<bool>

OnDeInitThread

Occurs on the worker thread when it terminates after initialization.

event Action OnDeInitThread

Event Type

Action

OnInitThread

Occurs on the worker thread before its first action executes.

event Action OnInitThread

Event Type

Action