Table of Contents

Class ScheduledAction

Namespace
CarinaStudio.Threading
Assembly
CarinaStudio.AppBase.Core.dll

Scheduled action which will be performed by specific SynchronizationContext. This is a thread-safe class.

public class ScheduledAction : ISynchronizable
Inheritance
ScheduledAction
Implements
Derived
Inherited Members
Extension Methods

Constructors

ScheduledAction(ISynchronizable, Action)

Initialize new ScheduledAction instance.

public ScheduledAction(ISynchronizable synchronizable, Action action)

Parameters

synchronizable ISynchronizable

ISynchronizable to provide SynchronizationContext to perform action.

action Action

Action.

ScheduledAction(Action)

Initialize new ScheduledAction instance with current SynchronizationContext.

public ScheduledAction(Action action)

Parameters

action Action

Action.

ScheduledAction(SynchronizationContext, Action)

Initialize new ScheduledAction instance.

public ScheduledAction(SynchronizationContext synchronizationContext, Action action)

Parameters

synchronizationContext SynchronizationContext

SynchronizationContext to perform action.

action Action

Action.

Properties

IsScheduled

Check whether execution has been scheduled or not.

public bool IsScheduled { get; }

Property Value

bool

SynchronizationContext

SynchronizationContext to perform action.

public SynchronizationContext SynchronizationContext { get; }

Property Value

SynchronizationContext

Methods

Cancel()

Cancel scheduled execution.

public bool Cancel()

Returns

bool

True if action has been cancelled.

CancelAction(object)

Cancel posted action.

protected virtual bool CancelAction(object token)

Parameters

token object

Token returned from PostAction(SendOrPostCallback, object?, int) to identify the posted action.

Returns

bool

True if action has been cancelled successfully.

Execute()

Execute action on current thread immediately. The scheduled execution will be cancelled.

public void Execute()

ExecuteIfScheduled()

Execute action on current thread immediately if execution has been scheduled. The scheduled execution will be cancelled.

public bool ExecuteIfScheduled()

Returns

bool

True if action has been executed.

PostAction(SendOrPostCallback, object?, int)

Post action to underlying synchronization context.

protected virtual object PostAction(SendOrPostCallback action, object? state, int delayMillis)

Parameters

action SendOrPostCallback

Action.

state object

State.

delayMillis int

Delay time in milliseconds.

Returns

object

Token to identify the posted action.

Reschedule()

Reschedule execution. It will replace the previous scheduling.

public void Reschedule()

Reschedule(int)

Reschedule execution. It will replace the previous scheduling.

public void Reschedule(int delayMillis)

Parameters

delayMillis int

Delay time in milliseconds.

Reschedule(TimeSpan)

Reschedule execution. It will replace the previous scheduling.

public void Reschedule(TimeSpan delay)

Parameters

delay TimeSpan

Delay time.

Schedule()

Schedule execution. It won't be scheduled again if execution is already scheduled.

public void Schedule()

Schedule(int)

Schedule execution. It won't be scheduled again if execution is already scheduled.

public void Schedule(int delayMillis)

Parameters

delayMillis int

Delay time in milliseconds.

Schedule(TimeSpan)

Schedule execution. It won't be scheduled again if execution is already scheduled.

public void Schedule(TimeSpan delay)

Parameters

delay TimeSpan

Delay time.