var appendFileResponse = await Policy
.HandleResult<HttpResponseMessage>(message => !message.IsSuccessStatusCode)
.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
.ExecuteAsync(async () => await httpClient.SendAsync(request).ConfigureAwait(true))
.ConfigureAwait(true);
if (appendFileResponse.StatusCode != System.Net.HttpStatusCode.Accepted)
{
throw new ApplicationException($"Failed to append file");
}在执行If检查和其他一些操作之前,我想确保appendFileResponse已完成。
我应该在httpClient.SendAsync调用中添加ConfigureAwait(true)和/或在等待策略中添加.ConfigureAwait(true)吗?
发布于 2020-05-02 08:36:18
ConfigureAwait对事物的运行顺序没有影响。您使用的是await,这意味着代码在这一点上将“异步等待”。
ConfigureAwait只确定which context your code is resuming on:捕获的上下文(默认)或线程池上下文(如果传递false的话)。
无论您是否使用ConfigureAwait,都会在所有Polly重试之后运行if。
https://stackoverflow.com/questions/61552799
复制相似问题