Skip to content

This example is not very useful #27830

@Seabizkit

Description

@Seabizkit

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions