-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
The reason
it is point less to have to wait for all task to be completed for the main task to be marked as cancelled.
example: why would you want this
// Task 1 executing
// Task 2 executing
// Task 3 executing
// Task 4 executing
// Task 5 executing
// Task 6 executing
// Task 7 executing
// Task 8 executing
// c
// Task cancellation requested.
// Task 2 cancelled
// Task 7 cancelled
//
// OperationCanceledException thrown
example: This is what you would want
// Task 1 executing
// Task 2 executing
// Task 3 executing
// Task 4 executing
// Task 5 executing
// Task 6 executing
// Task 7 executing
// c
// Task cancellation requested.
// Task 2 cancelled
// OperationCanceledException thrown
// Task 7 cancelled
// Task 8 cancelled
you dont want to have to wait for all to be cancelled before being allowed to cancel...
if you had 100 tasks and you are controlling the execution,
lets say its completed 40
then if it hasn't started x (60) tasks why would you want to wait for say
another x cancels to be processed before saying it cancelled.
another thing is DoSomeWork is not async, which in most modern use cases it would be aka
say the tasks were to download a file and then have retry logic ect. this would most like be async in side the DoSomeWork method.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: d994a93a-8eb5-9de3-d18f-121d8d63312f
- Version Independent ID: 8d25baef-270a-2af8-c96e-2bbc9da49640
- Content: How to: Cancel a Task and Its Children
- Content Source: docs/standard/parallel-programming/how-to-cancel-a-task-and-its-children.md
- Product: dotnet-fundamentals
- GitHub Login: @IEvangelist
- Microsoft Alias: dapine