Skip to content

Conversation

@Kissaki
Copy link
Contributor

@Kissaki Kissaki commented Jun 6, 2024

I attempted to fix #27830, but as per my comment there, I don't think the original raised concern is correct. I did make some improvements though, which are present in this changeset I am submitting.

This snippet is being used in "How to: Cancel a Task and Its Children" https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-cancel-a-task-and-its-children

The mixed four-fold goals of the how-to make it a complex mixed bag of an example.

  • For distinction, label tasks as cancellable, parent, and child - in output and variable names
  • Use output prefixes to indicate in which context the message is logged
  • Reduce wait spins (it took infeasibly long on my PC)
  • Reduce parent spawn-loop-spin-waits so spawning happens faster than child task execution
  • Add "ran to completion" messages so execution can be followed and user cancel can be timed and experimented with at runtime
  • Use CancelAsync instead of Cancel on tokenSource

I attempted to fix dotnet#27830, but as per my comment there, I don't think the original raised concern is correct. I did make some improvements though, which are present in this changeset I am submitting.

This snippet is being used in "How to: Cancel a Task and Its Children" https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-cancel-a-task-and-its-children

The mixed four-fold goals of the how-to make it a complex mixed bag of an example.

* For distinction, label tasks as cancellable, parent, and child - in output and variable names
* Use output prefixes to indicate in which context the message is logged
* Reduce wait spins (it took infeasibly long on my PC)
* Reduce parent spawn-loop-spin-waits so spawning happens faster than child task execution
* Add "ran to completion" messages so execution can be followed and user cancel can be timed and experimented with at runtime
* Use CancelAsync instead of Cancel on tokenSource
@dotnet-bot dotnet-bot added this to the June 2024 milestone Jun 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates PR is created by someone from the .NET community. label Jun 6, 2024
@Kissaki
Copy link
Contributor Author

Kissaki commented Jun 6, 2024

CI

Error: D:\a\docs\docs\samples\snippets\csharp\VS_Snippets_Misc\tpl_cancellation\cs\cancel1.cs(64,31): error CS1061: 'CancellationTokenSource' does not contain a definition for 'CancelAsync' and no accessible extension method 'CancelAsync' accepting a first argument of type 'CancellationTokenSource' could be found (are you missing a using directive or an assembly reference?) [D:\a\docs\docs\samples\snippets\csharp\VS_Snippets_Misc\tpl_cancellation\cs\Project.csproj::TargetFramework=net6.0]

So I guess it should remain Cancel.

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

Thanks @Kissaki

These changes all look good. I'll :shipit: now.

@BillWagner BillWagner merged commit 3488b02 into dotnet:main Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates PR is created by someone from the .NET community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

This example is not very useful

3 participants