File tree Expand file tree Collapse file tree 1 file changed +3
-1
lines changed
docs/fundamentals/networking/snippets/httpclient Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Original file line number Diff line number Diff line change 33 static async Task WithCancellationAndInnerTimeoutAsync ( HttpClient httpClient )
44 {
55 // <innertimeout>
6+ using var cts = new CancellationTokenSource ( ) ;
67 try
78 {
89 // Assuming:
910 // httpClient.Timeout = TimeSpan.FromSeconds(10)
1011
1112 using var response = await httpClient . GetAsync (
12- "http://localhost:5001/sleepFor?seconds=100" ) ;
13+ "http://localhost:5001/sleepFor?seconds=100" , cts . Token ) ;
1314 }
1415 catch ( OperationCanceledException ex ) when ( ex . InnerException is TimeoutException tex )
1516 {
17+ // when the time-out occurred. Here the cancellation token has not been canceled.
1618 Console . WriteLine ( $ "Timed out: { ex . Message } , { tex . Message } ") ;
1719 }
1820 // </innertimeout>
You can’t perform that action at this time.
0 commit comments