Click or drag to resize

LogicalThreadOperation Class

Synchronized operation that executes on a logical thread.
Inheritance Hierarchy
SystemObject
  GSF.ThreadingLogicalThreadOperation

Namespace: GSF.Threading
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.218-beta+101eee949414e414795e55a6e73d88938f0177b8
Syntax
public class LogicalThreadOperation
View Source

The LogicalThreadOperation type exposes the following members.

Constructors
 NameDescription
Public methodLogicalThreadOperation(LogicalThread, Action, Boolean) Creates a new instance of the LogicalThreadOperation class.
Public methodLogicalThreadOperation(LogicalThread, Action, Int32, Boolean) Creates a new instance of the LogicalThreadOperation class.
Top
Properties
 NameDescription
Public propertyAutoRunIfPending Gets flag that determines if RunIfPending will be called automatically.
Public propertyIsPending Gets a value to indicate whether the operation has an additional operation that is pending execution after the currently running operation has completed.
Public propertyIsRunning Gets a value to indicate whether the operation is currently executing actions.
Public propertyPriority Gets or sets default priority for logical thread operation.
Top
Methods
 NameDescription
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodExecuteAction Executes an action once on the current thread.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodRequeueAction If the operation is running, the action has yet to be executed, and the given priority level differs from the queued action's priority level, this method will requeue the action at the given priority level.
Public methodRunIfPending Starts the operation over at the beginning if the operation is pending or sets the operation state back to not running so it can run again.
Public methodRunOnce Executes the action on the current thread or marks the operation as pending if the operation is already running.
Public methodRunOnceAsync Executes the action on another thread or marks the operation as pending if the operation is already running.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Public methodTryRunOnce Attempts to execute the action on the current thread. Does nothing if the operation is already running.
Public methodTryRunOnceAsync Attempts to execute the action on another thread. Does nothing if the operation is already running.
Top
Extension Methods
 NameDescription
Public Extension MethodGetEnumValueOrDefault Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Public Extension MethodGetEnumValueOrDefaultT Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Top
Remarks
This synchronized operation optionally supports a different usage pattern which will allow for asynchronous loops and signals to be passed between threads throughout an operation. The following is an example of how to implement a simple asynchronous loop between two threads using this class. Note that when used, the pattern requires more diligence on the user's part for handling exceptions and signaling when the operation is complete:
C#
LogicalThread thread1 = new LogicalThread();
LogicalThread thread2 = new LogicalThread();

// Create logical thread operation with manually controlled call to RunIfPending
LogicalThreadOperation operation = new LogicalThreadOperation(thread1, DoOperation, false);

private void DoOperation()
{
    ExecuteOnThread1();
    thread2.Push(() => operation.ExecuteAction(() =>
    {
        ExecuteOnThread2();
        operation.RunIfPending();
    }));
});
See Also