Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
static async Task WithCancellationAndInnerTimeoutAsync(HttpClient httpClient)
{
// <innertimeout>
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}");
}
// </innertimeout>
Expand Down