Skip to content

DurableTaskContext

class

Namespace: Orleans.Durable.Tasks

Describes a running durable task and supplies its host's services.
public abstract class DurableTaskContext

Remarks

Task code reads the running task's context from DurableTask. Hosts derive from this type to schedule and record the task's operations.

An execution's code runs on one scheduler, the one which was current when the host created the context, such as its grain activation's scheduler, so the context's state needs no synchronization. The host creates the context, requests task cancellation, and cancels the attempt on that scheduler, and the execution's code allocates identifiers and runs effects there: an operation which code runs elsewhere, for example after `ConfigureAwait(false)`, throws System.InvalidOperationException. The cancellation tokens and the handles which the execution observes remain safe to use from any thread.

Constructors

Properties

  • AttemptCancellationReasonGets why this attempt was canceled, or null while it runs.
  • AttemptCancellationToken Gets the token which is canceled when the host cancels this attempt: its grain activation is stopping, or the task was aborted or deleted. Pass it to the calls which durable cleanup makes after task cancellation.
  • CancellationToken Gets the token which is canceled when durable cancellation of the task is requested or the host cancels this attempt. Pass it to the calls which ordinary task code makes.
  • HostId Gets the identity of the host which runs this execution, such as its grain, which qualifies the root identifiers which the execution derives for the detached tasks it starts, or null for none.
  • IdGets this execution's identifier.
  • IncarnationGets the nonce which identifies the run of the root task which this execution belongs to.
  • IsAttemptCanceledGets a value indicating whether this attempt was canceled, by the host or by a divergence of its replay.
  • IsReplaying Gets a value indicating whether this run of the task's body is re-running operations which an earlier run recorded. Use it for logging and diagnostics only.
  • IsTaskCancellationRequestedGets a value indicating whether durable cancellation of the task has been requested.
  • SchedulesShieldedChildren Gets whether the calling code runs within a DurableTaskExtensions start of this execution, so that a child which it schedules isn't reached by this execution's durable cancellation.
  • TaskCancellationReason Gets the reason which the durable cancellation request carries, or null when task cancellation hasn't been requested or its request carries no reason.
  • UtcNowGets the host-provided logical UTC time for this execution.

Methods