We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d3870c3 commit 5777abcCopy full SHA for 5777abc
1 file changed
docs/fundamentals/networking/snippets/httpclient/Program.CancellationInnerTimeout.cs
@@ -3,16 +3,18 @@
3
static async Task WithCancellationAndInnerTimeoutAsync(HttpClient httpClient)
4
{
5
// <innertimeout>
6
+ using var cts = new CancellationTokenSource();
7
try
8
9
// Assuming:
10
// httpClient.Timeout = TimeSpan.FromSeconds(10)
11
12
using var response = await httpClient.GetAsync(
- "http://localhost:5001/sleepFor?seconds=100");
13
+ "http://localhost:5001/sleepFor?seconds=100", cts.Token);
14
}
15
catch (OperationCanceledException ex) when (ex.InnerException is TimeoutException tex)
16
17
+ // when the time-out occurred. Here the cancellation token has not been canceled.
18
Console.WriteLine($"Timed out: {ex.Message}, {tex.Message}");
19
20
// </innertimeout>
0 commit comments