小编use*_*949的帖子

如何在通过 Polly 重试策略执行的委托中获取重试计数?

我正在实施 Polly 以在我的 C# Web 应用程序中重试请求。我的示例代码包含在这篇文章中。代码按预期工作,但传递给 CreateFile() 的最后一个参数(当前硬编码为 0)需要是 retryAttempt 的值。如何在执行操作中获取 retryAttempt 的值?

return Policy
    .Handle<HttpException>(x => x.StatusCode == (HttpStatusCode)429)
    .Or<StorageException>()
    .WaitAndRetry(maxRetryCount, retryAttempt => TimeSpan.FromMilliseconds(Math.Pow(retryIntervalMs, retryAttempt)))
    .Execute(() => CreateFile(fileContent, containerName, fileName, connectionString, 0));
Run Code Online (Sandbox Code Playgroud)

c# polly retry-logic

5
推荐指数
1
解决办法
3252
查看次数

标签 统计

c# ×1

polly ×1

retry-logic ×1