Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
For new C# HTTP clients, use Microsoft’s Microsoft.Extensions.Http.Resilience package with IHttpClientFactory. Register the client with AddHttpClient and attach AddStandardResilienceHandler for a bounded retry, timeout, rate-limiting, and circuit-breaker pipeline. Before enabling retries, decide whether the request can safely run again: the standard handler retries all HTTP methods by default, so a retried write can duplicate a side effect.
Use the current .NET HTTP resilience package
Microsoft recommends Microsoft.Extensions.Http.Resilience for resilience policies on HttpClient. The older Microsoft.Extensions.Http.Polly package is deprecated; Microsoft directs developers to Microsoft.Extensions.Http.Resilience or Microsoft.Extensions.Resilience. Older examples using AddPolicyHandler or WaitAndRetryAsync describe a legacy integration rather than the current recommended setup. See Microsoft’s HTTP resilience guidance and .NET resilience guidance.
Add the package that matches your target framework and register a typed client. This is a configuration pattern, not a guarantee that the defaults suit every API; check the package version and the target framework’s API compatibility before adopting it.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
using System.Net.Http.Headers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Http.Resilience;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddHttpClient<MyApiClient>(client =>
{
client.BaseAddress = new Uri("https://api.example.com/");
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
})
.AddStandardResilienceHandler(options =>
{
// Avoid automatically repeating methods that may have side effects.
options.Retry.DisableForUnsafeHttpMethods();
});
var app = builder.Build();
app.Run();
public sealed class MyApiClient(HttpClient httpClient)
{
public Task<HttpResponseMessage> GetAsync(
string path, CancellationToken cancellationToken = default) =>
httpClient.GetAsync(path, cancellationToken);
}
The namespace and registration extensions come from the resilience package. In an existing application, keep dependency registration in its normal startup location and inject the typed client where it is needed. Do not create a new HttpClient for every request; its lifetime and connection pooling are separate concerns from retry policy.
#1 Best Overall
What the standard handler retries—and what it does not
Microsoft documents the standard HTTP retry strategy as handling responses with status codes 500 and above, 408 Request Timeout, and 429 Too Many Requests, as well as HttpRequestException and Polly’s TimeoutRejectedException. These are candidates for retry because a later attempt may succeed without changing the request. They are not proof that retrying is safe for the operation.
Authentication failures and validation errors generally need a changed credential or payload, so repeating the same request is unlikely to help. A service’s Retry-After response header can indicate when to try again; the current HttpRetryStrategyOptions API exposes ShouldRetryAfterHeader to use that header when determining delay. Confirm the configured policy for the package version you use. Sources: HTTP resilience in .NET and HttpRetryStrategyOptions API reference.
Standard pipeline defaults are starting points
Microsoft documents the standard handler as a pipeline that includes a rate limiter, total timeout, retry strategy, and circuit breaker. Its documented defaults include three retries, exponential backoff, jitter enabled, a two-second delay setting, and a 30-second total timeout. These are library defaults, not measured performance guarantees or a universal recommendation. Check them against the remote service’s guidance, the operation’s deadline, and your application’s latency budget.
Rank #2
A retry count means retries after the initial attempt. Thus, three configured retries can produce as many as four executions of the operation. The pipeline also has a circuit breaker: unlike retrying an individual failure, it can temporarily stop calls when failures persist, then permit a later trial. The timeout bounds time spent by the pipeline, while the rate limiter helps control concurrent requests. Consult Microsoft’s documented strategy order and defaults when tuning the combined behavior.
Make retries safe for the HTTP method and operation
The standard handler retries all HTTP methods by default. That includes methods often used for writes. Consider a POST that creates an order: the server may commit the order, but the response may be lost. A retry can create a second order unless the API supports idempotency or deduplication.
- Safe reads: Retrying a GET is usually less likely to create a side effect, but still consider whether the endpoint has unusual behavior and whether the extra load is acceptable.
- Writes with API-supported idempotency: Use the API’s documented idempotency key or deduplication mechanism consistently across attempts. A new key per retry may defeat deduplication.
- Writes without an idempotency guarantee: Disable automatic retries for them, or handle the ambiguous outcome through application-specific reconciliation rather than blindly resending.
For a client that should not retry unsafe methods, the example uses options.Retry.DisableForUnsafeHttpMethods(). Microsoft documents this helper as excluding POST, PATCH, PUT, DELETE, and CONNECT. The API also exposes DisableFor when you need to exclude specific methods. These controls prevent a general retry rule from silently applying to operations that can change server state. See the retry options API.
Choose a retry budget that fits the request
Retries trade a greater chance of eventual success for added latency and traffic. Bound both attempts and total time: a call that retries beyond the caller’s deadline is not useful, and a large number of simultaneous retries can add pressure to a degraded service.
- Use a bounded retry count. Remember that the initial call is additional to the configured retry count.
- Prefer backoff with jitter for transient failures. Exponential backoff increases spacing between attempts; jitter varies timing so many clients are less likely to retry in synchrony.
- Respect service instructions. Where appropriate, use
Retry-Afterrather than assuming a local delay is more suitable. - Set an overall deadline. Coordinate the resilience pipeline timeout with the caller’s cancellation token and the user-facing or job-processing deadline.
- Keep retries from multiplying across layers. If an upstream caller, HTTP handler, and job runner each retry, the number of downstream attempts can grow quickly. Assign retry ownership deliberately.
The standard handler provides one documented baseline, but Microsoft also supports AddResilienceHandler for a custom pipeline when you need different predicates, retry limits, or strategy ordering. Use a custom policy when the endpoint’s semantics or latency requirements differ materially from the standard defaults.
Keep HttpClient connections healthy
Retry configuration does not solve connection management. Microsoft recommends either a long-lived HttpClient with PooledConnectionLifetime chosen to suit expected DNS or network changes, or clients created through IHttpClientFactory. A typed client registered with AddHttpClient uses the factory approach.
Rank #4
Creating and disposing a new HttpClient for every request can cause unnecessary connection creation and port exhaustion. There is also a cookie consideration: factory pooling shares handler and cookie-container state. That may be unsuitable when an application requires isolated cookies. Review Microsoft’s HttpClient guidelines and choose a lifetime strategy that matches your connection and cookie requirements.
Customize the policy when defaults are not enough
Use AddStandardResilienceHandler when its defined strategies and defaults are a reasonable starting point. Use AddResilienceHandler when the endpoint needs a custom retry predicate, different limits, or a different strategy composition. Keep custom behavior narrow: retry only failures that can plausibly clear without changing the request, and preserve safeguards for operations with side effects.
Before changing the policy, identify which status codes and exceptions the service can return, whether it documents retry timing, whether the operation is idempotent, and the maximum time the caller can wait. Then verify the behavior against the documentation for the exact package version you deploy. Microsoft’s HTTP resilience documentation describes both the standard and custom handler approaches.
Best Value
Troubleshoot common retry problems
- The code does not compile for
AddStandardResilienceHandlerorDisableForUnsafeHttpMethods. Check that the project referencesMicrosoft.Extensions.Http.Resilience, that the relevant namespaces are imported, and that the installed package version supports the API used. Verify compatibility with the target framework. - A request appears to run four times. Three retries means up to three repeats after the initial attempt, or four executions total. Check retry counts at every layer, not just the HTTP handler.
- A POST or other write creates duplicates. The standard handler retries all methods unless configured otherwise. Exclude unsafe methods or use the remote API’s supported idempotency or deduplication mechanism.
- A request keeps retrying an error that needs a fix. Authentication and validation problems generally require a changed credential or payload. Review the retry predicate and avoid treating permanent failures as transient.
- Retries do not follow the server’s suggested delay. Inspect the response’s
Retry-Afterheader and confirm the configuredShouldRetryAfterHeaderbehavior in the version in use. - Latency exceeds the caller’s expectation. Account for all attempts, backoff delays, and the total pipeline timeout; align them with the caller’s cancellation and deadline.
- Connections or cookies behave unexpectedly. Review whether the application creates clients per request, how
IHttpClientFactorypools handlers, and whether shared cookie-container state is appropriate.
Or skip the browser setup
If your C# work also needs website screenshots, ScreenshotNeo is a separate option: it is a website screenshot API and MCP server, not an HTTP retry library. One GET request can return a PNG, JPEG, WebP, or PDF. Its clean-shot flow accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers indicating the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for setup and request options. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.
Frequently Asked Questions
Should I retry HTTP 400 responses?
The documented standard retry strategy covers HTTP 408, 429, and 500-or-higher responses, not all 4xx responses. A 400 validation error ordinarily needs a corrected request rather than an identical retry.
Does a retry count include the first request?
No. The configured count is additional retries; three retries can mean four total executions including the initial request.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

