public class TaskSynchronizedOperation : ISynchronizedOperation
Public Class TaskSynchronizedOperation
Implements ISynchronizedOperation
public ref class TaskSynchronizedOperation : ISynchronizedOperation
Gemstone.Threading.SynchronizedOperations.TaskSynchronizedOperation = function();
Type.createClass(
'Gemstone.Threading.SynchronizedOperations.TaskSynchronizedOperation',
null,
Gemstone.Threading.SynchronizedOperations.ISynchronizedOperation);
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.
public ExampleClass() =>
SynchronizedOperation = new TaskSynchronizedOperation(NotifyAsync);
public void SendNotification() =>
SynchronizedOperation.RunOnceAsync();
private async Task NotifyAsync()
{
Notify();
await Task.Delay(15000);
}
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. |
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. |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
MemberwiseClone | Creates 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. |
ToString | Returns 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. |