Skip to content

Mistake in example for listening for cancellation requests by polling #31643

Closed
@stephanus-redstor

Description

@stephanus-redstor

What happens if the token is cancelled after the if (token.IsCancellationRequested) {}, but before the evaluation of the outer for loop? The outer for loop's conditions won't be met and thus won't execute again. The function will return without ever executing the cleanup code inside the inner if statement (in the example it's only Console.WriteLine stuff, but in real life it might be important stuff like freeing up vast amounts of resources)?


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions