TaskSynchronizedOperation Class

Represents a task-based synchronized operation that cannot run while it is already in progress.

Definition

Namespace: Gemstone.Threading.SynchronizedOperations
Assembly: Gemstone.Threading (in Gemstone.Threading.dll) Version: 1.0.110 -- Release Build+13c244059615c58a533059438f38d7e59ef0c2ea
public class TaskSynchronizedOperation : ISynchronizedOperation
Inheritance
Object    TaskSynchronizedOperation
Implements
ISynchronizedOperation

Remarks

The action performed by the TaskSynchronizedOperation is executed using Run(FuncTask). Pending actions run when the task returned by the asynchronous action is completed. This synchronized operation only supports the async methods on the ISynchronizedOperation interface because the async action cannot be executed synchronously.

The following example shows how to use TaskSynchronizedOperation to implement a notifier that receives notification requests ad-hoc but sends notifications no more than once every 15 seconds.

C#
public ExampleClass() =>
    SynchronizedOperation = new TaskSynchronizedOperation(NotifyAsync);

public void SendNotification() =>
    SynchronizedOperation.RunOnceAsync();

private async Task NotifyAsync()
{
    Notify();
    await Task.Delay(15000);
}

Constructors

TaskSynchronizedOperation(FuncTask) Creates a new instance of the TaskSynchronizedOperation class.
TaskSynchronizedOperation(FuncCancellationToken, Task) Creates a new instance of the TaskSynchronizedOperation class.
TaskSynchronizedOperation(FuncTask, ActionException) Creates a new instance of the TaskSynchronizedOperation class.
TaskSynchronizedOperation(FuncCancellationToken, Task, ActionException) Creates a new instance of the TaskSynchronizedOperation class.

Properties

CancellationToken Gets or sets CancellationToken to use for canceling actions.
IsPending Gets a value to indicate whether the synchronized operation has an additional operation that is pending execution after the currently running action has completed.
IsRunning Gets a value to indicate whether the synchronized operation is currently executing its action.

Methods

EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
RunAsync Executes the action on another thread or marks the operation as pending if the operation is already running.
ToStringReturns a string that represents the current object.
(Inherited from Object)
TryRunAsync Attempts to execute the action on another thread. Does nothing if the operation is already running.

See Also