diff --git a/docs/fundamentals/networking/snippets/httpclient/Program.CancellationInnerTimeout.cs b/docs/fundamentals/networking/snippets/httpclient/Program.CancellationInnerTimeout.cs index 0ce9788c986f7..7ab607f98ab67 100644 --- a/docs/fundamentals/networking/snippets/httpclient/Program.CancellationInnerTimeout.cs +++ b/docs/fundamentals/networking/snippets/httpclient/Program.CancellationInnerTimeout.cs @@ -3,16 +3,18 @@ static async Task WithCancellationAndInnerTimeoutAsync(HttpClient httpClient) { // + using var cts = new CancellationTokenSource(); try { // Assuming: // httpClient.Timeout = TimeSpan.FromSeconds(10) using var response = await httpClient.GetAsync( - "http://localhost:5001/sleepFor?seconds=100"); + "http://localhost:5001/sleepFor?seconds=100", cts.Token); } catch (OperationCanceledException ex) when (ex.InnerException is TimeoutException tex) { + // when the time-out occurred. Here the cancellation token has not been canceled. Console.WriteLine($"Timed out: {ex.Message}, {tex.Message}"); } //