C# Class GSF.Threading.SynchronizedOperationBase

Base class for operations that cannot run while they is already in progress.
This class handles the synchronization between the methods defined in the ISynchronizedOperation interface. Implementers should only need to implement the ExecuteActionAsync method to provide a mechanism for executing the action on a separate thread.
Inheritance: ISynchronizedOperation
显示文件 Open project: GridProtectionAlliance/gsf

Public Methods

Method Description
Run ( ) : void

Executes the action on this thread or marks the operation as pending if the operation is already running.

When the operation is marked as pending, it will run again after the operation that is currently running has completed. This is useful if an update has invalidated the operation that is currently running and will therefore need to be run again.

This method does not guarantee that control will be returned to the thread that called it. If other threads continuously mark the operation as pending, this thread will continue to run the operation indefinitely.

RunOnce ( ) : void

Executes the action on this thread or marks the operation as pending if the operation is already running.

When the operation is marked as pending, it will run again after the operation that is currently running has completed. This is useful if an update has invalidated the operation that is currently running and will therefore need to be run again.

RunOnceAsync ( ) : void

Executes the action on another thread or marks the operation as pending if the operation is already running.

When the operation is marked as pending, it will run again after the operation that is currently running has completed. This is useful if an update has invalidated the operation that is currently running and will therefore need to be run again.

TryRun ( ) : void

Attempts to execute the action on this thread. Does nothing if the operation is already running.

This method does not guarantee that control will be returned to the thread that called it. If other threads continuously mark the operation as pending, this thread will continue to run the operation indefinitely.

TryRunOnce ( ) : void

Attempts to execute the action on this thread. Does nothing if the operation is already running.

TryRunOnceAsync ( ) : void

Attempts to execute the action on another thread. Does nothing if the operation is already running.

Protected Methods

Method Description
ExecuteAction ( ) : bool

Executes the action once on the current thread.

ExecuteActionAsync ( ) : void

Executes the action on a separate thread.

Implementers should call ExecuteAction on a separate thread and check the return value. If it returns true, that means it needs to run again. The following is a sample implementation using a regular dedicated thread. protected override void ExecuteActionAsync() { Thread actionThread = new Thread(() => { while (ExecuteAction()) { } }); actionThread.Start(); }

SynchronizedOperationBase ( System.Action action ) : System

Creates a new instance of the SynchronizedOperationBase class.

SynchronizedOperationBase ( System.Action action, Action exceptionAction ) : System

Creates a new instance of the SynchronizedOperationBase class.

Method Details

ExecuteAction() protected method

Executes the action once on the current thread.
protected ExecuteAction ( ) : bool
return bool

ExecuteActionAsync() protected abstract method

Executes the action on a separate thread.
Implementers should call ExecuteAction on a separate thread and check the return value. If it returns true, that means it needs to run again. The following is a sample implementation using a regular dedicated thread. protected override void ExecuteActionAsync() { Thread actionThread = new Thread(() => { while (ExecuteAction()) { } }); actionThread.Start(); }
protected abstract ExecuteActionAsync ( ) : void
return void

Run() public method

Executes the action on this thread or marks the operation as pending if the operation is already running.

When the operation is marked as pending, it will run again after the operation that is currently running has completed. This is useful if an update has invalidated the operation that is currently running and will therefore need to be run again.

This method does not guarantee that control will be returned to the thread that called it. If other threads continuously mark the operation as pending, this thread will continue to run the operation indefinitely.

public Run ( ) : void
return void

RunOnce() public method

Executes the action on this thread or marks the operation as pending if the operation is already running.
When the operation is marked as pending, it will run again after the operation that is currently running has completed. This is useful if an update has invalidated the operation that is currently running and will therefore need to be run again.
public RunOnce ( ) : void
return void

RunOnceAsync() public method

Executes the action on another thread or marks the operation as pending if the operation is already running.
When the operation is marked as pending, it will run again after the operation that is currently running has completed. This is useful if an update has invalidated the operation that is currently running and will therefore need to be run again.
public RunOnceAsync ( ) : void
return void

SynchronizedOperationBase() protected method

Creates a new instance of the SynchronizedOperationBase class.
protected SynchronizedOperationBase ( System.Action action ) : System
action System.Action The action to be performed during this operation.
return System

SynchronizedOperationBase() protected method

Creates a new instance of the SynchronizedOperationBase class.
protected SynchronizedOperationBase ( System.Action action, Action exceptionAction ) : System
action System.Action The action to be performed during this operation.
exceptionAction Action The action to be performed if an exception is thrown from the action.
return System

TryRun() public method

Attempts to execute the action on this thread. Does nothing if the operation is already running.
This method does not guarantee that control will be returned to the thread that called it. If other threads continuously mark the operation as pending, this thread will continue to run the operation indefinitely.
public TryRun ( ) : void
return void

TryRunOnce() public method

Attempts to execute the action on this thread. Does nothing if the operation is already running.
public TryRunOnce ( ) : void
return void

TryRunOnceAsync() public method

Attempts to execute the action on another thread. Does nothing if the operation is already running.
public TryRunOnceAsync ( ) : void
return void