Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions docs/develop/dotnet/workflows/cancellation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,18 @@ public async Task RunAsync()

// Call cleanup activity. If this throws, it will swallow the original exception which we
// are ok with here. This could be changed to just log a failure and let the original
// cancellation continue. We use a different cancellation token since the default one on
// Workflow.CancellationToken is now marked cancelled.
using var detachedCancelSource = new CancellationTokenSource();
// cancellation continue.
// The default token on Workflow.CancellationToken is now marked
// cancelled, so we pass a different one. We use CancellationToken.None here because the
// cleanup activity itself doesn't need to be cancellable; if it did (e.g. you want to
// cancel cleanup from a timeout or another signal), create a new detached
// CancellationTokenSource and pass its Token instead.
await Workflow.ExecuteActivityAsync(
(MyActivities a) => a.MyCancellationCleanupActivity(),
new()
{
ScheduleToCloseTimeout = TimeSpan.FromMinutes(5),
CancellationToken = detachedCancelSource.Token;
CancellationToken = CancellationToken.None,
});

// Rethrow the cancellation
Expand Down
Loading