Skip to content

Grain Methods

The abstract base class for all grain classes.

DeactivateOnIdle

View source
protected void DeactivateOnIdle()
Deactivate this activation of the grain after the current grain method call is completed. This call will mark this activation of the current grain to be deactivated and removed at the end of the current method. The next call to this grain will result in a different activation to be used, which typical means a new activation will be created automatically by the runtime.

DelayDeactivation(TimeSpan)

View source
protected void DelayDeactivation(TimeSpan timeSpan)
Delay Deactivation of this activation at least for the specified time duration.

A positive timeSpan value means “prevent GC of this activation for that time span”.

A System.TimeSpan.Zero value means “cancel the previous setting of the Grain call and make this activation behave based on the regular Activation Garbage Collection settings”.

A System.Threading.Timeout.InfiniteTimeSpan value means “delay deactivation indefinitely”.

Grain would undo / override any current “keep alive” setting, making this grain immediately available for deactivation.

Parameters

timeSpanTimeSpan

MigrateOnIdle

View source
protected void MigrateOnIdle()
Starts an attempt to migrating this instance to another location. Migration captures the current RequestContext, making it available to the activation's placement director so that it can consider it when selecting a new location. Migration will occur asynchronously, when no requests are executing, and will not occur if the activation's placement director does not select an alternative location.

OnActivateAsync(CancellationToken)

virtual
View source
public virtual Task OnActivateAsync(CancellationToken cancellationToken)
This method is called at the end of the process of activating a grain. It is called before any messages have been dispatched to the grain. For grains with declared persistent state, this method is called after the State property has been populated.

Parameters

cancellationTokenCancellationToken
A cancellation token which signals when activation is being canceled.

OnDeactivateAsync(DeactivationReason, CancellationToken)

virtual
View source
public virtual Task OnDeactivateAsync(DeactivationReason reason, CancellationToken cancellationToken)
This method is called at the beginning of the process of deactivating a grain.

Parameters

reasonDeactivationReason
The reason for deactivation. Informational only.
cancellationTokenCancellationToken
A cancellation token which signals when deactivation should complete promptly.

RegisterTimer(Func<object?, Task>, object?, TimeSpan, TimeSpan)

View source
[System.Obsolete(Use 'this.RegisterGrainTimer(callback, state, new() { DueTime = dueTime, Period = period, Interleave = true })' instead.)]
protected IDisposable RegisterTimer(Func<object?, Task> callback, object? state, TimeSpan dueTime, TimeSpan period)
Registers a timer to send periodic callbacks to this grain.

Parameters

callbackFunc<object?, Task>
Callback function to be invoked when timer ticks.
stateobject?
State object that will be passed as argument when calling the callback.
dueTimeTimeSpan
Due time for first timer tick.
periodTimeSpan
Period of subsequent timer ticks.

Returns

Handle for this timer.