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
synchronizableISynchronizableISynchronizable to provide SynchronizationContext to perform action.
actionActionAction.
ScheduledAction(Action)
Initialize new ScheduledAction instance with current SynchronizationContext.
public ScheduledAction(Action action)
Parameters
actionActionAction.
ScheduledAction(SynchronizationContext, Action)
Initialize new ScheduledAction instance.
public ScheduledAction(SynchronizationContext synchronizationContext, Action action)
Parameters
synchronizationContextSynchronizationContextSynchronizationContext to perform action.
actionActionAction.
Properties
IsScheduled
Check whether execution has been scheduled or not.
public bool IsScheduled { get; }
Property Value
SynchronizationContext
SynchronizationContext to perform action.
public SynchronizationContext SynchronizationContext { get; }
Property Value
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
tokenobjectToken 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
actionSendOrPostCallbackAction.
stateobjectState.
delayMillisintDelay 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
delayMillisintDelay time in milliseconds.
Reschedule(TimeSpan)
Reschedule execution. It will replace the previous scheduling.
public void Reschedule(TimeSpan delay)
Parameters
delayTimeSpanDelay 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
delayMillisintDelay time in milliseconds.
Schedule(TimeSpan)
Schedule execution. It won't be scheduled again if execution is already scheduled.
public void Schedule(TimeSpan delay)
Parameters
delayTimeSpanDelay time.