Table of Contents

Class Workflow

Namespace
Temporalio.Workflows
Assembly
Temporalio.dll

Static class with all calls that can be made from a workflow. Properties and methods on this class cannot be used outside of a workflow (with the obvious exception of InWorkflow).

public static class Workflow
Inheritance
Workflow
Inherited Members

Properties

CancellationToken

Gets the cancellation token for the workflow.

public static CancellationToken CancellationToken { get; }

Property Value

CancellationToken

Remarks

This token is cancelled when the workflow is cancelled. When cancellation token is not provided to any method in this class, this cancellation token is the default.

ContinueAsNewSuggested

Gets a value indicating whether continue as new is suggested.

public static bool ContinueAsNewSuggested { get; }

Property Value

bool

Remarks

This value is the current continue-as-new suggestion up until the current task. Note, this value may not be up to date when accessed in a query. When continue as new is suggested is based on server-side configuration.

CurrentBuildId

Gets the current build id.

public static string CurrentBuildId { get; }

Property Value

string

Remarks

This is the Build ID of the worker which executed the current Workflow Task. It may be empty if the task was completed by a worker without a Build ID. If this worker is the one executing this task for the first time and has a Build ID set, then its ID will be used. This value may change over the lifetime of the workflow run, but is deterministic and safe to use for branching.

CurrentHistoryLength

Gets the current number of events in history.

public static int CurrentHistoryLength { get; }

Property Value

int

Remarks

This value is the current history event count up until the current task. Note, this value may not be up to date when accessed in a query.

CurrentHistorySize

Gets the current history size in bytes.

public static int CurrentHistorySize { get; }

Property Value

int

Remarks

This value is the current history size up until the current task. Note, this value may not be up to date when accessed in a query.

DynamicQuery

Gets or sets the current dynamic query handler. This can be null for no dynamic query handling.

public static WorkflowQueryDefinition? DynamicQuery { get; set; }

Property Value

WorkflowQueryDefinition

DynamicSignal

Gets or sets the current dynamic signal handler. This can be null for no dynamic signal handling. If this is set to a value where none was there before, all buffered signals will be immediately delivered to it.

public static WorkflowSignalDefinition? DynamicSignal { get; set; }

Property Value

WorkflowSignalDefinition

DynamicUpdate

Gets or sets the current dynamic update handler. This can be null for no dynamic update handling.

public static WorkflowUpdateDefinition? DynamicUpdate { get; set; }

Property Value

WorkflowUpdateDefinition

InWorkflow

Gets a value indicating whether this code is currently running in a workflow.

public static bool InWorkflow { get; }

Property Value

bool

Info

Gets information about the workflow.

public static WorkflowInfo Info { get; }

Property Value

WorkflowInfo

Logger

Gets the logger for the workflow. This is scoped with logger information and does not log during replay.

public static ILogger Logger { get; }

Property Value

ILogger

Memo

Gets the workflow memo.

public static IReadOnlyDictionary<string, IRawValue> Memo { get; }

Property Value

IReadOnlyDictionary<string, IRawValue>

Remarks

This is read-only from the workflow author perspective. To update use UpsertMemo(params MemoUpdate[]). This always returns the same instance. Any workflow memo updates are immediately reflected on the returned instance, so it is not immutable.

MetricMeter

Gets the metric meter with per-workflow tags already set. Metrics can be set on this meter and they will be properly ignored during replay. This meter is different for each workflow execution.

public static MetricMeter MetricMeter { get; }

Property Value

MetricMeter

PayloadConverter

Gets the payload converter for the workflow.

public static IPayloadConverter PayloadConverter { get; }

Property Value

IPayloadConverter

Queries

Gets queries for this workflow.

public static IDictionary<string, WorkflowQueryDefinition> Queries { get; }

Property Value

IDictionary<string, WorkflowQueryDefinition>

Remarks

This dictionary can be mutated during workflow run. However, users are strongly encouraged to use fixed methods with the [WorkflowQuery] attribute.

Random

Gets a random instance that is deterministic for workflow use.

public static DeterministicRandom Random { get; }

Property Value

DeterministicRandom

Remarks

This instance should be accessed each time needed, not stored. This instance may be recreated with a different seed in special cases (e.g. workflow reset). Do not use any other randomization inside workflow code.

Signals

Gets signals for this workflow.

public static IDictionary<string, WorkflowSignalDefinition> Signals { get; }

Property Value

IDictionary<string, WorkflowSignalDefinition>

Remarks

This dictionary can be mutated during workflow run. However, users are strongly encouraged to use fixed methods with the [WorkflowSignal] attribute. If a new signal handler is added for a signal name where one wasn't present before, all buffered signals are sent to the handler immediately.

TypedSearchAttributes

Gets the workflow search attributes.

public static SearchAttributeCollection TypedSearchAttributes { get; }

Property Value

SearchAttributeCollection

Remarks

This is read-only from the workflow author perspective. To update use UpsertTypedSearchAttributes(params SearchAttributeUpdate[]). This always returns the same instance. Any workflow search attribute updates are immediately reflected on the returned instance, so it is not immutable.

Updates

Gets updates for this workflow.

public static IDictionary<string, WorkflowUpdateDefinition> Updates { get; }

Property Value

IDictionary<string, WorkflowUpdateDefinition>

Remarks

This dictionary can be mutated during workflow run. However, users are strongly encouraged to use fixed methods with the [WorkflowUpdate] attribute.

UtcNow

Gets the current timestamp for this workflow.

public static DateTime UtcNow { get; }

Property Value

DateTime

Remarks

This value is deterministic and safe for replays. Do not use normal UtcNow or anything else dealing with system time in workflows.

Methods

CreateContinueAsNewException(string, IReadOnlyCollection<object?>, ContinueAsNewOptions?)

Create an exception that, when thrown out of the workflow, will continue-as-new with the given workflow.

public static ContinueAsNewException CreateContinueAsNewException(string workflow, IReadOnlyCollection<object?> args, ContinueAsNewOptions? options = null)

Parameters

workflow string

Workflow name.

args IReadOnlyCollection<object>

Workflow arguments.

options ContinueAsNewOptions

Continue as new options.

Returns

ContinueAsNewException

Exception for continuing as new.

CreateContinueAsNewException<TWorkflow>(Expression<Func<TWorkflow, Task>>, ContinueAsNewOptions?)

Create an exception via lambda invoking the run method that, when thrown out of the workflow, will continue-as-new with the given workflow.

public static ContinueAsNewException CreateContinueAsNewException<TWorkflow>(Expression<Func<TWorkflow, Task>> workflowRunCall, ContinueAsNewOptions? options = null)

Parameters

workflowRunCall Expression<Func<TWorkflow, Task>>

Invocation of workflow run method with a result.

options ContinueAsNewOptions

Continue as new options.

Returns

ContinueAsNewException

Exception for continuing as new.

Type Parameters

TWorkflow

Workflow class type.

CreateContinueAsNewException<TWorkflow, TResult>(Expression<Func<TWorkflow, Task<TResult>>>, ContinueAsNewOptions?)

Create an exception via lambda invoking the run method that, when thrown out of the workflow, will continue-as-new with the given workflow.

public static ContinueAsNewException CreateContinueAsNewException<TWorkflow, TResult>(Expression<Func<TWorkflow, Task<TResult>>> workflowRunCall, ContinueAsNewOptions? options = null)

Parameters

workflowRunCall Expression<Func<TWorkflow, Task<TResult>>>

Invocation of workflow run method with a result.

options ContinueAsNewOptions

Continue as new options.

Returns

ContinueAsNewException

Exception for continuing as new.

Type Parameters

TWorkflow

Workflow class type.

TResult

Workflow result type.

DelayAsync(int, CancellationToken?)

Sleep in a workflow for the given time. See documentation of DelayAsync(TimeSpan, CancellationToken?) for details.

public static Task DelayAsync(int millisecondsDelay, CancellationToken? cancellationToken = null)

Parameters

millisecondsDelay int

Delay amount. See documentation of DelayAsync(TimeSpan, CancellationToken?) for details.

cancellationToken CancellationToken?

Cancellation token. See documentation of DelayAsync(TimeSpan, CancellationToken?) for details.

Returns

Task

Task for completion. See documentation of DelayAsync(TimeSpan, CancellationToken?) for details.

See Also

DelayAsync(TimeSpan, CancellationToken?)

Sleep in a workflow for the given time.

public static Task DelayAsync(TimeSpan delay, CancellationToken? cancellationToken = null)

Parameters

delay TimeSpan

Amount of time to sleep.

cancellationToken CancellationToken?

Cancellation token. If unset, this defaults to CancellationToken.

Returns

Task

Task that is complete when sleep completes.

Remarks

The delay value can be Infinite or InfiniteTimeSpan but otherwise cannot be negative. A server-side timer is not created for infinite delays, so it is non-deterministic to change a timer to/from infinite from/to an actual value.

If the delay is 0, it is assumed to be 1 millisecond and still results in a server-side timer. Since Temporal timers are server-side, timer resolution may not end up as precise as system timers.

DeprecatePatch(string)

Mark a patch as deprecated.

public static void DeprecatePatch(string patchId)

Parameters

patchId string

Patch ID.

Remarks

This marks a workflow that had Patched(string) in a previous version of the code as no longer applicable because all workflows that use the old code path are done and will never be queried again. Therefore the old code path is removed as well.

ExecuteActivityAsync(Expression<Action>, ActivityOptions)

Execute a static non-async activity without result via lambda.

public static Task ExecuteActivityAsync(Expression<Action> activityCall, ActivityOptions options)

Parameters

activityCall Expression<Action>

Invocation of activity method.

options ActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task

Task for completion with result.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteActivityAsync(Expression<Func<Task>>, ActivityOptions)

Execute a static async activity without result via lambda.

public static Task ExecuteActivityAsync(Expression<Func<Task>> activityCall, ActivityOptions options)

Parameters

activityCall Expression<Func<Task>>

Invocation of activity method.

options ActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task

Task for completion with result.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteActivityAsync(string, IReadOnlyCollection<object?>, ActivityOptions)

Execute an activity by name with no result and any number of arguments.

public static Task ExecuteActivityAsync(string activity, IReadOnlyCollection<object?> args, ActivityOptions options)

Parameters

activity string

Activity name to execute.

args IReadOnlyCollection<object>

Activity arguments.

options ActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task

Task for completion.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteActivityAsync<TActivityInstance>(Expression<Action<TActivityInstance>>, ActivityOptions)

Execute a non-static non-async activity without result via lambda.

public static Task ExecuteActivityAsync<TActivityInstance>(Expression<Action<TActivityInstance>> activityCall, ActivityOptions options)

Parameters

activityCall Expression<Action<TActivityInstance>>

Invocation of activity method.

options ActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task

Task for completion with result.

Type Parameters

TActivityInstance

Activity class type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteActivityAsync<TResult>(Expression<Func<Task<TResult>>>, ActivityOptions)

Execute a static async activity with result via lambda.

public static Task<TResult> ExecuteActivityAsync<TResult>(Expression<Func<Task<TResult>>> activityCall, ActivityOptions options)

Parameters

activityCall Expression<Func<Task<TResult>>>

Invocation of activity method.

options ActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task<TResult>

Task for completion with result.

Type Parameters

TResult

Activity result type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteActivityAsync<TActivityInstance>(Expression<Func<TActivityInstance, Task>>, ActivityOptions)

Execute a non-static async activity without result via lambda.

public static Task ExecuteActivityAsync<TActivityInstance>(Expression<Func<TActivityInstance, Task>> activityCall, ActivityOptions options)

Parameters

activityCall Expression<Func<TActivityInstance, Task>>

Invocation of activity method.

options ActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task

Task for completion with result.

Type Parameters

TActivityInstance

Activity class type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteActivityAsync<TResult>(Expression<Func<TResult>>, ActivityOptions)

Execute a static non-async activity with result via lambda.

public static Task<TResult> ExecuteActivityAsync<TResult>(Expression<Func<TResult>> activityCall, ActivityOptions options)

Parameters

activityCall Expression<Func<TResult>>

Invocation of activity method.

options ActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task<TResult>

Task for completion with result.

Type Parameters

TResult

Activity result type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteActivityAsync<TResult>(string, IReadOnlyCollection<object?>, ActivityOptions)

Execute an activity by name with a result and any number of arguments.

public static Task<TResult> ExecuteActivityAsync<TResult>(string activity, IReadOnlyCollection<object?> args, ActivityOptions options)

Parameters

activity string

Activity name to execute.

args IReadOnlyCollection<object>

Activity arguments.

options ActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task<TResult>

Task for completion with result.

Type Parameters

TResult

Activity result type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteActivityAsync<TActivityInstance, TResult>(Expression<Func<TActivityInstance, Task<TResult>>>, ActivityOptions)

Execute a non-static async activity with result via lambda.

public static Task<TResult> ExecuteActivityAsync<TActivityInstance, TResult>(Expression<Func<TActivityInstance, Task<TResult>>> activityCall, ActivityOptions options)

Parameters

activityCall Expression<Func<TActivityInstance, Task<TResult>>>

Invocation of activity method.

options ActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task<TResult>

Task for completion with result.

Type Parameters

TActivityInstance

Activity class type.

TResult

Activity result type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteActivityAsync<TActivityInstance, TResult>(Expression<Func<TActivityInstance, TResult>>, ActivityOptions)

Execute a non-static non-async activity with result via lambda.

public static Task<TResult> ExecuteActivityAsync<TActivityInstance, TResult>(Expression<Func<TActivityInstance, TResult>> activityCall, ActivityOptions options)

Parameters

activityCall Expression<Func<TActivityInstance, TResult>>

Invocation of activity method.

options ActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task<TResult>

Task for completion with result.

Type Parameters

TActivityInstance

Activity class type.

TResult

Activity result type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteChildWorkflowAsync(string, IReadOnlyCollection<object?>, ChildWorkflowOptions?)

public static Task ExecuteChildWorkflowAsync(string workflow, IReadOnlyCollection<object?> args, ChildWorkflowOptions? options = null)

Parameters

workflow string

Workflow name to execute.

args IReadOnlyCollection<object>

Workflow arguments.

options ChildWorkflowOptions

Workflow options.

Returns

Task

Task for workflow completion.

Remarks

Using an already-cancelled token may give a different exception than cancelling after started. Use IsCanceledException(Exception) to check if it's a cancellation either way.

ExecuteChildWorkflowAsync<TWorkflow>(Expression<Func<TWorkflow, Task>>, ChildWorkflowOptions?)

public static Task ExecuteChildWorkflowAsync<TWorkflow>(Expression<Func<TWorkflow, Task>> workflowRunCall, ChildWorkflowOptions? options = null)

Parameters

workflowRunCall Expression<Func<TWorkflow, Task>>

Invocation of workflow run method with a result.

options ChildWorkflowOptions

Workflow options.

Returns

Task

Task for workflow completion.

Type Parameters

TWorkflow

Workflow class type.

Remarks

Using an already-cancelled token may give a different exception than cancelling after started. Use IsCanceledException(Exception) to check if it's a cancellation either way.

ExecuteChildWorkflowAsync<TResult>(string, IReadOnlyCollection<object?>, ChildWorkflowOptions?)

public static Task<TResult> ExecuteChildWorkflowAsync<TResult>(string workflow, IReadOnlyCollection<object?> args, ChildWorkflowOptions? options = null)

Parameters

workflow string

Workflow name to execute.

args IReadOnlyCollection<object>

Workflow arguments.

options ChildWorkflowOptions

Workflow options.

Returns

Task<TResult>

Task for workflow completion.

Type Parameters

TResult

Workflow result type.

Remarks

Using an already-cancelled token may give a different exception than cancelling after started. Use IsCanceledException(Exception) to check if it's a cancellation either way.

ExecuteChildWorkflowAsync<TWorkflow, TResult>(Expression<Func<TWorkflow, Task<TResult>>>, ChildWorkflowOptions?)

public static Task<TResult> ExecuteChildWorkflowAsync<TWorkflow, TResult>(Expression<Func<TWorkflow, Task<TResult>>> workflowRunCall, ChildWorkflowOptions? options = null)

Parameters

workflowRunCall Expression<Func<TWorkflow, Task<TResult>>>

Invocation of workflow run method with a result.

options ChildWorkflowOptions

Workflow options.

Returns

Task<TResult>

Task for workflow completion.

Type Parameters

TWorkflow

Workflow class type.

TResult

Workflow result type.

Remarks

Using an already-cancelled token may give a different exception than cancelling after started. Use IsCanceledException(Exception) to check if it's a cancellation either way.

ExecuteLocalActivityAsync(Expression<Action>, LocalActivityOptions)

Execute a static non-async local activity without result via lambda.

public static Task ExecuteLocalActivityAsync(Expression<Action> activityCall, LocalActivityOptions options)

Parameters

activityCall Expression<Action>

Invocation of activity method.

options LocalActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task

Task for completion with result.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteLocalActivityAsync(Expression<Func<Task>>, LocalActivityOptions)

Execute a static async local activity without result via lambda.

public static Task ExecuteLocalActivityAsync(Expression<Func<Task>> activityCall, LocalActivityOptions options)

Parameters

activityCall Expression<Func<Task>>

Invocation of activity method.

options LocalActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task

Task for completion with result.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteLocalActivityAsync(string, IReadOnlyCollection<object?>, LocalActivityOptions)

Execute a local activity by name with no result and any number of arguments.

public static Task ExecuteLocalActivityAsync(string activity, IReadOnlyCollection<object?> args, LocalActivityOptions options)

Parameters

activity string

Activity name to execute.

args IReadOnlyCollection<object>

Activity arguments.

options LocalActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task

Task for completion.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteLocalActivityAsync<TActivityInstance>(Expression<Action<TActivityInstance>>, LocalActivityOptions)

Execute a non-static non-async local activity without result via lambda.

public static Task ExecuteLocalActivityAsync<TActivityInstance>(Expression<Action<TActivityInstance>> activityCall, LocalActivityOptions options)

Parameters

activityCall Expression<Action<TActivityInstance>>

Invocation of activity method.

options LocalActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task

Task for completion with result.

Type Parameters

TActivityInstance

Activity class type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteLocalActivityAsync<TResult>(Expression<Func<Task<TResult>>>, LocalActivityOptions)

Execute a static async local activity with result via lambda.

public static Task<TResult> ExecuteLocalActivityAsync<TResult>(Expression<Func<Task<TResult>>> activityCall, LocalActivityOptions options)

Parameters

activityCall Expression<Func<Task<TResult>>>

Invocation of activity method.

options LocalActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task<TResult>

Task for completion with result.

Type Parameters

TResult

Activity result type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteLocalActivityAsync<TActivityInstance>(Expression<Func<TActivityInstance, Task>>, LocalActivityOptions)

Execute a non-static async local activity without result via lambda.

public static Task ExecuteLocalActivityAsync<TActivityInstance>(Expression<Func<TActivityInstance, Task>> activityCall, LocalActivityOptions options)

Parameters

activityCall Expression<Func<TActivityInstance, Task>>

Invocation of activity method.

options LocalActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task

Task for completion with result.

Type Parameters

TActivityInstance

Activity class type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteLocalActivityAsync<TResult>(Expression<Func<TResult>>, LocalActivityOptions)

Execute a static non-async local activity with result via lambda.

public static Task<TResult> ExecuteLocalActivityAsync<TResult>(Expression<Func<TResult>> activityCall, LocalActivityOptions options)

Parameters

activityCall Expression<Func<TResult>>

Invocation of activity method.

options LocalActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task<TResult>

Task for completion with result.

Type Parameters

TResult

Activity result type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteLocalActivityAsync<TResult>(string, IReadOnlyCollection<object?>, LocalActivityOptions)

Execute a local activity by name with a result and any number of arguments.

public static Task<TResult> ExecuteLocalActivityAsync<TResult>(string activity, IReadOnlyCollection<object?> args, LocalActivityOptions options)

Parameters

activity string

Activity name to execute.

args IReadOnlyCollection<object>

Activity arguments.

options LocalActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task<TResult>

Task for completion with result.

Type Parameters

TResult

Activity result type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteLocalActivityAsync<TActivityInstance, TResult>(Expression<Func<TActivityInstance, Task<TResult>>>, LocalActivityOptions)

Execute a non-static async local activity with result via lambda.

public static Task<TResult> ExecuteLocalActivityAsync<TActivityInstance, TResult>(Expression<Func<TActivityInstance, Task<TResult>>> activityCall, LocalActivityOptions options)

Parameters

activityCall Expression<Func<TActivityInstance, Task<TResult>>>

Invocation of activity method.

options LocalActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task<TResult>

Task for completion with result.

Type Parameters

TActivityInstance

Activity class type.

TResult

Activity result type.

Remarks

The task will throw an ActivityFailureException on activity failure.

ExecuteLocalActivityAsync<TActivityInstance, TResult>(Expression<Func<TActivityInstance, TResult>>, LocalActivityOptions)

Execute a non-static non-async local activity with result via lambda.

public static Task<TResult> ExecuteLocalActivityAsync<TActivityInstance, TResult>(Expression<Func<TActivityInstance, TResult>> activityCall, LocalActivityOptions options)

Parameters

activityCall Expression<Func<TActivityInstance, TResult>>

Invocation of activity method.

options LocalActivityOptions

Activity options. This is required and either ScheduleToCloseTimeout or StartToCloseTimeout must be set.

Returns

Task<TResult>

Task for completion with result.

Type Parameters

TActivityInstance

Activity class type.

TResult

Activity result type.

Remarks

The task will throw an ActivityFailureException on activity failure.

GetExternalWorkflowHandle(string, string?)

Get a handle to an external workflow for cancelling and issuing signals.

public static ExternalWorkflowHandle GetExternalWorkflowHandle(string id, string? runId = null)

Parameters

id string

Workflow ID.

runId string

Optional workflow run ID.

Returns

ExternalWorkflowHandle

External workflow handle.

GetExternalWorkflowHandle<TWorkflow>(string, string?)

Get a handle to an external workflow for cancelling and issuing signals.

public static ExternalWorkflowHandle<TWorkflow> GetExternalWorkflowHandle<TWorkflow>(string id, string? runId = null)

Parameters

id string

Workflow ID.

runId string

Optional workflow run ID.

Returns

ExternalWorkflowHandle<TWorkflow>

External workflow handle.

Type Parameters

TWorkflow

Workflow class type.

NewGuid()

Deterministically create a new Guid similar to NewGuid() (which cannot be used in workflows). The resulting GUID intentionally represents a version 4 UUID.

public static Guid NewGuid()

Returns

Guid

A new GUID.

Patched(string)

Patch a workflow.

public static bool Patched(string patchId)

Parameters

patchId string

Patch ID.

Returns

bool

True if this should take the newer patch, false if it should take the old path.

Remarks

When called, this will only return true if code should take the newer path which means this is either not replaying or is replaying and has seen this patch before. Results for successive calls to this function for the same ID and workflow are memoized.

Use DeprecatePatch(string) when all workflows are done and will never be queried again. The old code path can be removed at that time too.

StartChildWorkflowAsync(string, IReadOnlyCollection<object?>, ChildWorkflowOptions?)

Start a child workflow by name.

public static Task<ChildWorkflowHandle> StartChildWorkflowAsync(string workflow, IReadOnlyCollection<object?> args, ChildWorkflowOptions? options = null)

Parameters

workflow string

Workflow name to execute.

args IReadOnlyCollection<object>

Workflow arguments.

options ChildWorkflowOptions

Workflow options.

Returns

Task<ChildWorkflowHandle>

The child workflow handle once started.

Remarks

The task can throw a WorkflowAlreadyStartedException if an ID is given in the options but it is already running.

StartChildWorkflowAsync<TWorkflow>(Expression<Func<TWorkflow, Task>>, ChildWorkflowOptions?)

Start a child workflow via lambda invoking the run method.

public static Task<ChildWorkflowHandle<TWorkflow>> StartChildWorkflowAsync<TWorkflow>(Expression<Func<TWorkflow, Task>> workflowRunCall, ChildWorkflowOptions? options = null)

Parameters

workflowRunCall Expression<Func<TWorkflow, Task>>

Invocation of workflow run method without a result.

options ChildWorkflowOptions

Workflow options.

Returns

Task<ChildWorkflowHandle<TWorkflow>>

The child workflow handle once started.

Type Parameters

TWorkflow

Workflow class type.

Remarks

The task can throw a WorkflowAlreadyStartedException if an ID is given in the options but it is already running.

StartChildWorkflowAsync<TWorkflow, TResult>(Expression<Func<TWorkflow, Task<TResult>>>, ChildWorkflowOptions?)

Start a child workflow via lambda invoking the run method.

public static Task<ChildWorkflowHandle<TWorkflow, TResult>> StartChildWorkflowAsync<TWorkflow, TResult>(Expression<Func<TWorkflow, Task<TResult>>> workflowRunCall, ChildWorkflowOptions? options = null)

Parameters

workflowRunCall Expression<Func<TWorkflow, Task<TResult>>>

Invocation of workflow run method with a result.

options ChildWorkflowOptions

Workflow options.

Returns

Task<ChildWorkflowHandle<TWorkflow, TResult>>

The child workflow handle once started.

Type Parameters

TWorkflow

Workflow class type.

TResult

Workflow result type.

Remarks

The task can throw a WorkflowAlreadyStartedException if an ID is given in the options but it is already running.

UpsertMemo(params MemoUpdate[])

Issue updates to the workflow memo.

public static void UpsertMemo(params MemoUpdate[] updates)

Parameters

updates MemoUpdate[]

Updates to issue.

Exceptions

ArgumentException

If no updates given, two updates are given for a key, or an update value cannot be converted.

UpsertTypedSearchAttributes(params SearchAttributeUpdate[])

Issue updates to the workflow search attributes.

public static void UpsertTypedSearchAttributes(params SearchAttributeUpdate[] updates)

Parameters

updates SearchAttributeUpdate[]

Updates to issue.

Exceptions

ArgumentException

If no updates given or two updates are given for a key.

WaitConditionAsync(Func<bool>, int, CancellationToken?)

Wait for the given function to return true or a timeout. See documentation of WaitConditionAsync(Func<bool>, TimeSpan, CancellationToken?) for more details.

public static Task<bool> WaitConditionAsync(Func<bool> conditionCheck, int timeoutMilliseconds, CancellationToken? cancellationToken = null)

Parameters

conditionCheck Func<bool>

Condition function. See documentation of WaitConditionAsync(Func<bool>, TimeSpan, CancellationToken?) for more details.

timeoutMilliseconds int

Timeout milliseconds. See documentation of WaitConditionAsync(Func<bool>, TimeSpan, CancellationToken?) for more details.

cancellationToken CancellationToken?

Cancellation token. See documentation of WaitConditionAsync(Func<bool>, TimeSpan, CancellationToken?) for more details.

Returns

Task<bool>

Task when condition becomes true or a timeout has occurred. See documentation of WaitConditionAsync(Func<bool>, TimeSpan, CancellationToken?) for more details.

See Also

WaitConditionAsync(Func<bool>, CancellationToken?)

Wait for the given function to return true. See documentation of WaitConditionAsync(Func<bool>, TimeSpan, CancellationToken?) for more details.

public static Task WaitConditionAsync(Func<bool> conditionCheck, CancellationToken? cancellationToken = null)

Parameters

conditionCheck Func<bool>

Condition function. See documentation of WaitConditionAsync(Func<bool>, TimeSpan, CancellationToken?) for more details.

cancellationToken CancellationToken?

Cancellation token. See documentation of WaitConditionAsync(Func<bool>, TimeSpan, CancellationToken?) for more details.

Returns

Task

Task when condition becomes true. See documentation of WaitConditionAsync(Func<bool>, TimeSpan, CancellationToken?) for more details.

See Also

WaitConditionAsync(Func<bool>, TimeSpan, CancellationToken?)

Wait for the given function to return true or a timeout.

public static Task<bool> WaitConditionAsync(Func<bool> conditionCheck, TimeSpan timeout, CancellationToken? cancellationToken = null)

Parameters

conditionCheck Func<bool>

Condition function.

timeout TimeSpan

Optional timeout for waiting.

cancellationToken CancellationToken?

Cancellation token. If unset, this defaults to CancellationToken.

Returns

Task<bool>

Task with true when condition becomes true or false if a timeout occurs.

Remarks

The conditionCheck function is invoked on each iteration of the event loop. Therefore, it should be fast and side-effect free.

WhenAnyAsync(IEnumerable<Task>)

Workflow-safe form of WhenAny(IEnumerable<Task>).

public static Task<Task> WhenAnyAsync(IEnumerable<Task> tasks)

Parameters

tasks IEnumerable<Task>

Tasks to wait for first completed of.

Returns

Task<Task>

First completed task.

WhenAnyAsync(params Task[])

Workflow-safe form of WhenAny(params Task[]).

public static Task<Task> WhenAnyAsync(params Task[] tasks)

Parameters

tasks Task[]

Tasks to wait for first completed of.

Returns

Task<Task>

First completed task.

WhenAnyAsync<TResult>(IEnumerable<Task<TResult>>)

public static Task<Task<TResult>> WhenAnyAsync<TResult>(IEnumerable<Task<TResult>> tasks)

Parameters

tasks IEnumerable<Task<TResult>>

Tasks to wait for first completed of.

Returns

Task<Task<TResult>>

First completed task.

Type Parameters

TResult

Result type.

WhenAnyAsync<TResult>(params Task<TResult>[])

public static Task<Task<TResult>> WhenAnyAsync<TResult>(params Task<TResult>[] tasks)

Parameters

tasks Task<TResult>[]

Tasks to wait for first completed of.

Returns

Task<Task<TResult>>

First completed task.

Type Parameters

TResult

Result type.