3.22Setting the Timeout
Created on Aug 17, 2026~2 min read
Sets the timeout duration for a single request.
HttpRequestBuilder.Get("https://furion.net/") .SetTimeout(TimeSpan.FromSeconds(2));HttpRequestBuilder.Get("https://furion.net/") .SetTimeout(2000); // Unit is millisecondsHttpRequestBuilder.Get("https://furion.net/") .SetTimeout(-1); // Never times out; or use .WithoutTimeout(), or set System.Threading.Timeout.InfiniteTimeSpanHttpRequestBuilder.Get("https://furion.net/") .SetTimeout(0); // Immediately cancels the requestHttpRequestBuilder.Get("https://furion.net/") .SetTimeout(TimeSpan.FromSeconds(2), () => // Supports a timeout callback { // Action to execute when a timeout occurs });HttpRequestBuilder.Get("https://furion.net/") .SetTimeout(2000, () => // Supports a timeout callback { // Action to execute when a timeout occurs });HttpRequestBuilder.Get("https://furion.net/") .SetTimeout(new HttpTimeoutOptions()); // Custom timeout optionsHttpRequestBuilder.Get("https://furion.net/") .SetTimeout(options => options.SetTimeout(2000)); // Custom timeout optionsTo limit the maximum total elapsed time, including retries and wait times, use an external CancellationTokenSource:
// Limit the total elapsed time of the entire process (including retries) to no more than 2 secondsusing var timeoutCancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(2));var builder = HttpRequestBuilder.Get("https://furion.net/") .SetTimeout(500) // Single request timeout of 500 ms .SetRetry(5, TimeSpan.FromSeconds(1)); // Allow 5 retries with a 1-second interval between each// Pass a global Token to terminate the entire process immediately at 2 secondsvar response = await httpRemoteService.SendAsync(builder, timeoutCancellationToken.Token);