An asynchronous task was cancelled before completion via CancellationToken.
Thrown when an `async` operation managed by a `CancellationToken` times out or is explicitly cancelled.
HTTP requests taking longer than `HttpClient.Timeout`, or manually invoking `CancellationTokenSource.Cancel()` during long operations.
1using System;2using System.Net.Http;3using System.Threading.Tasks;4 5public class Program {6 public static async Task Main() {7 using var client = new HttpClient { Timeout = TimeSpan.FromMilliseconds(10) };8 // Request takes longer than 10ms timeout!9 var response = await client.GetAsync("https://httpbin.org/delay/2"); // Throws TaskCanceledException10 }11}1using System;2using System.Net.Http;3using System.Threading.Tasks;4 5public class Program {6 public static async Task Main() {7 using var client = new HttpClient { Timeout = TimeSpan.FromSeconds(10) };8 try {9 var response = await client.GetAsync("https://httpbin.org/delay/1");10 Console.WriteLine($"Status: {response.StatusCode}");11 } catch (TaskCanceledException) {12 Console.WriteLine("Request timed out or was cancelled gracefully.");13 }14 }15}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
Because request execution time exceeds the configured 10ms HTTP client timeout, the internal `CancellationToken` triggers cancellation.