Click or drag to resize

LogicalThread Class

Represents a thread of execution to which actions can be dispatched from other threads.
Inheritance Hierarchy
SystemObject
  GSF.ThreadingLogicalThread

Namespace: GSF.Threading
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.207-beta+1781b796b2aa7a54013a031eb432fe4ccee31867
Syntax
public class LogicalThread
View Source

The LogicalThread type exposes the following members.

Constructors
 NameDescription
Public methodLogicalThread Creates a new instance of the LogicalThread class.
Top
Properties
 NameDescription
Public propertyStatic memberCurrentThread Gets the logical thread that is currently executing.
Public propertyHasAction Gets a flag that indicates whether the logical thread has any unprocessed actions left in its queue.
Public propertyPriorityLevels Gets the number of levels of priority supported by this logical thread.
Top
Methods
 NameDescription
Public methodClear Clears all actions from the logical thread.
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
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 methodPush(Action) Pushes an action to the logical thread.
Public methodPush(Int32, Action) Pushes an action to the logical thread.
Public methodSampleStatistics Samples the statistics, providing current statistic values and resetting statistic counters.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Events
 NameDescription
Public eventUnhandledException Handler for unhandled exceptions on the thread.
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)
Public Extension MethodJoin Creates an awaitable that ensures the continuation is running on the logical thread.
(Defined by LogicalThreadExtensions)
Public Extension MethodJoin Creates an awaitable that ensures the continuation is running on the logical thread.
(Defined by LogicalThreadExtensions)
Public Extension MethodYield Creates an awaitable that asynchronously yields to a new action on the logical thread when awaited.
(Defined by LogicalThreadExtensions)
Public Extension MethodYield Creates an awaitable that asynchronously yields to a new action on the logical thread when awaited.
(Defined by LogicalThreadExtensions)
Top
Remarks

This class provides a simple alternative to synchronization primitives such as wait handles and locks. Actions dispatched to a logical thread will be processed synchronously as though it was executed as consecutive method calls. All such actions can be dispatched from any thread in the system so method calls coming from multiple threads can be easily synchronized without locks, loops, wait handles, or timeouts.

Note that the LogicalThreadScheduler implements its own thread pool to execute tasks pushed to logical threads. Executing long-running processes or using synchronization primitives with high contention or long timeouts can hinder the logical thread scheduler's ability to schedule the actions of other logical threads. Like other thread pool implementations, you can mitigate this by increasing the maximum thread count of the logical thread scheduler, however it is recommended to avoid using synchronization primitives and instead synchronize those operations by running them as separate actions on the same logical thread.

See Also