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
Afficher le fichier Open project: GridProtectionAlliance/gsf

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

Executes the action once on the current thread.
protected ExecuteAction ( ) : bool
Résultat bool

ExecuteActionAsync() protected abstract méthode

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
Résultat void

Run() public méthode

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
Résultat void

RunOnce() public méthode

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
Résultat void

RunOnceAsync() public méthode

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
Résultat void

SynchronizedOperationBase() protected méthode

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.
Résultat System

SynchronizedOperationBase() protected méthode

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.
Résultat System

TryRun() public méthode

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
Résultat void

TryRunOnce() public méthode

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

TryRunOnceAsync() public méthode

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