Class ThreadSafeOneTimeAction
Thread-safe utility for executing an action exactly once across multiple threads. Uses lock-free atomic operations.
Inheritance
System.Object
ThreadSafeOneTimeAction
Namespace: Eco.Core.Utils
Assembly: Eco.Core.dll
Syntax
public sealed class ThreadSafeOneTimeAction : Object
Constructors
ThreadSafeOneTimeAction()
Declaration
public ThreadSafeOneTimeAction()
Properties
WasExecuted
Declaration
public bool WasExecuted { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Methods
Reset()
Resets the execution state, allowing the action to be executed again.
Declaration
public void Reset()
TryExecute(Action)
Attempts to execute the action. If this is the first call across all threads, executes the action. Subsequent calls do nothing.
Declaration
public void TryExecute(Action action)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Action | action |
TryExecute<T>(Action<T>, T)
Attempts to execute the action with a parameter. If this is the first call across all threads, executes the action. Subsequent calls do nothing.
Declaration
public void TryExecute<T>(Action<T> action, T parameter)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Action<T> | action | |
| T | parameter |
Type Parameters
| Name | Description |
|---|---|
| T |
TryReset(Action)
Attempts to reset if the action was previously executed, and optionally executes a reset action.
Declaration
public bool TryReset(Action onResetAction = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Action | onResetAction |
Returns
| Type | Description |
|---|---|
| System.Boolean |