diff --git a/docs/develop/dotnet/workflows/cancellation.mdx b/docs/develop/dotnet/workflows/cancellation.mdx index 9ca83fffa5..0900ef0b36 100644 --- a/docs/develop/dotnet/workflows/cancellation.mdx +++ b/docs/develop/dotnet/workflows/cancellation.mdx @@ -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