Skip to main content

Schedules - .NET SDK feature guide

This page shows how to do the following:

Schedule a Workflow

How to Schedule a Workflow using the Temporal .NET SDK

Scheduling Workflows is a crucial aspect of any automation process, especially when dealing with time-sensitive tasks. By scheduling a Workflow, you can automate repetitive tasks, reduce the need for manual intervention, and ensure timely execution of your business processes

Use any of the following action to help Schedule a Workflow Execution and take control over your automation process.

Create a Scheduled Workflow

How to create a Scheduled Workflow using the Temporal .NET SDK

The create action enables you to create a new Schedule. When you create a new Schedule, a unique Schedule ID is generated, which you can use to reference the Schedule in other Schedule commands.

To create a Scheduled Workflow Execution in .NET, use the CreateScheduleAsync method on the Client. Then pass the Schedule ID and the Schedule object to the method to create a Scheduled Workflow Execution. Set the Schedule's Action property to an instance of ScheduleActionStartWorkflow to schedule a Workflow Execution.

using Temporalio.Client;
using Temporalio.Client.Schedules;

var client = await TemporalClient.ConnectAsync(new("localhost:7233"));

var handle = await client.CreateScheduleAsync(
"my-schedule-id",
new(
Action: ScheduleActionStartWorkflow.Create(
(MyWorkflow wf) => wf.RunAsync(),
new(id: "my-workflow-id", taskQueue: "my-task-queue")),
Spec: new()
{
Intervals = new List<ScheduleIntervalSpec> { new(Every: TimeSpan.FromDays(5)) },
}));

Backfill a Scheduled Workflow

How to backfill a Scheduled Workflow using the Temporal .NET SDK

The backfill action executes Actions ahead of their specified time range. This command is useful when you need to execute a missed or delayed Action, or when you want to test the Workflow before its scheduled time.

To backfill a Scheduled Workflow Execution in .NET, use the BackfillAsync() method on the Schedule Handle.

using Temporalio.Client;
using Temporalio.Client.Schedules;

var client = await TemporalClient.ConnectAsync(new("localhost:7233"));

var handle = client.GetScheduleHandle("my-schedule-id");
var now = DateTime.Now;
await handle.BackfillAsync(new List<ScheduleBackfill>
{
new(
StartAt: now - TimeSpan.FromDays(30),
EndAt: now - TimeSpan.FromDays(20),
Overlap: ScheduleOverlapPolicy.AllowAll),
});

Delete a Scheduled Workflow

How to delete a Scheduled Workflow using the Temporal .NET SDK

The delete action enables you to delete a Schedule. When you delete a Schedule, it does not affect any Workflows that were started by the Schedule.

To delete a Scheduled Workflow Execution in .NET, use the DeleteAsync() method on the Schedule Handle.

using Temporalio.Client;
using Temporalio.Client.Schedules;

var client = await TemporalClient.ConnectAsync(new("localhost:7233"));

var handle = client.GetScheduleHandle("my-schedule-id");
await handle.DeleteAsync();

Describe a Scheduled Workflow

How to describe a Scheduled Workflow using the Temporal .NET SDK

The describe action shows the current Schedule configuration, including information about past, current, and future Workflow Runs. This command is helpful when you want to get a detailed view of the Schedule and its associated Workflow Runs.

To describe a Scheduled Workflow Execution in .NET, use the DescribeAsync() method on the Schedule Handle.

using Temporalio.Client;
using Temporalio.Client.Schedules;

var client = await TemporalClient.ConnectAsync(new("localhost:7233"));

var handle = client.GetScheduleHandle("my-schedule-id");
var desc = await handle.DescribeAsync();
Console.WriteLine("Schedule info: {0}", desc.Info);

List a Scheduled Workflow

How to list a Scheduled Workflow using the Temporal .NET SDK

The list action lists all the available Schedules. This command is useful when you want to view a list of all the Schedules and their respective Schedule IDs.

To list all schedules, use the ListSchedulesAsync() asynchronous method on the Client. This returns an async enumerable. If a schedule is added or deleted, it may not be available in the list immediately.

using Temporalio.Client;
using Temporalio.Client.Schedules;

var client = await TemporalClient.ConnectAsync(new("localhost:7233"));
await foreach (var desc in client.ListSchedulesAsync())
{
Console.WriteLine("Schedule info: {0}", desc.Info);
}

Pause a Scheduled Workflow

How to pause a Scheduled Workflow using the Temporal .NET SDK

The pause action enables you to pause and unpause a Schedule. When you pause a Schedule, all the future Workflow Runs associated with the Schedule are temporarily stopped. This command is useful when you want to temporarily halt a Workflow due to maintenance or any other reason.

To pause a Scheduled Workflow Execution in .NET, use the PauseAsync() method on the Schedule Handle. You can pass a note to the PauseAsync() method to provide a reason for pausing the schedule.

using Temporalio.Client;
using Temporalio.Client.Schedules;

var client = await TemporalClient.ConnectAsync(new("localhost:7233"));

var handle = client.GetScheduleHandle("my-schedule-id");
await handle.PauseAsync("Pausing the schedule for now");

Trigger a Scheduled Workflow

How to trigger a Scheduled Workflow using the Temporal .NET SDK

The trigger action triggers an immediate action with a given Schedule. By default, this action is subject to the Overlap Policy of the Schedule. This command is helpful when you want to execute a Workflow outside of its scheduled time.

To trigger a Scheduled Workflow Execution in .NET, use the TriggerAsync() method on the Schedule Handle.

using Temporalio.Client;
using Temporalio.Client.Schedules;

var client = await TemporalClient.ConnectAsync(new("localhost:7233"));

var handle = client.GetScheduleHandle("my-schedule-id");
await handle.TriggerAsync();

Update a Scheduled Workflow

How to update a Scheduled Workflow using the Temporal .NET SDK

The update action enables you to update an existing Schedule. This command is useful when you need to modify the Schedule's configuration, such as changing the start time, end time, or interval.

To update a Scheduled Workflow Execution in .NET, use the UpdateAsync() method on the Schedule Handle. This method accepts a callback that provides input with the current schedule. A new schedule can be created and returned from that callback to perform the update.

using Temporalio.Client;
using Temporalio.Client.Schedules;

var client = await TemporalClient.ConnectAsync(new("localhost:7233"));

var handle = client.GetScheduleHandle("my-schedule-id");
await handle.UpdateAsync(input =>
{
var newAction = ScheduleActionStartWorkflow.Create(
(MyWorkflow wf) => wf.RunAsync(),
new(id: "my-workflow-id", taskQueue: "my-task-queue"));
return new(input.Description.Schedule with { Action = newAction });
});

Use Start Delay

How to use Start Delay using the Temporal .NET SDK

Use the StartDelay to schedule a Workflow Execution at a specific one-time future point rather than on a recurring schedule.

Use the StartDelay option on WorkflowOptions in either the StartWorkflowAsync() or ExecuteWorkflowAsync() methods in the Client.

var handle = await client.StartWorkflowAsync(
(MyWorkflow wf) => wf.RunAsync(),
new(id: "my-workflow-id", taskQueue: "my-task-queue")
{
StartDelay = TimeSpan.FromHours(3),
});