Closed
Description
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.
- ID: 51f5ff8f-7d37-af59-4b51-41de21d67b95
- Version Independent ID: ef30d618-f141-3943-b93b-ce697ca8991b
- Content: Cancellation in Managed Threads
- Content Source: docs/standard/threading/cancellation-in-managed-threads.md
- Product: dotnet-fundamentals
- GitHub Login: @BillWagner
- Microsoft Alias: wiwagn