Skip to content

Use CancellationTokenSource.CancelAsync with a compatibility shim - #284

Open
Solution-lab wants to merge 2 commits into
madelson:masterfrom
Solution-lab:fix/265-cancel-async
Open

Use CancellationTokenSource.CancelAsync with a compatibility shim#284
Solution-lab wants to merge 2 commits into
madelson:masterfrom
Solution-lab:fix/265-cancel-async

Conversation

@Solution-lab

Copy link
Copy Markdown

Fixes #265.

  • Adds a CancellationTokenSource.CancelAsync() compatibility shim for frameworks older than .NET 8.
  • Uses the native CancelAsync() implementation on .NET 8.
  • Replaces background Task.Run(() => cts.Cancel()) calls with CancelAsync().
  • Adds a test verifying that cancellation does not block on callbacks.

Tested on .NET 8 and .NET Framework 4.7.2.

finally
{
cancellationTokenSource.Dispose();
}

@madelson madelson Aug 23, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's collapse this back to just 2 lines of code like the original (formatting)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make a shim for CancelAsync() and leverage that in places

2 participants