2
我在一个Xamarin项目中使用Polly,它工作得非常好。我面临的问题是,2次重试后,它应该继续该方法,但由于某种原因,它会卡住并继续重试。有谁知道我该怎么做?Polly在X重试后继续
private async Task<List<EventDto>> GetEventsErrorRemoteAsync()
{
List<EventDto> conferences = null;
if (CrossConnectivity.Current.IsConnected)
{
// Retrying a specific amount of times (5)
// In this case will wait for
// 1^2 = 2 seconds then
// 2^2 = 4 seconds then
// 3^2 = 8 seconds then
// 4^2 = 16 seconds then
// 5^2 = 32 seconds
conferences = await Policy
.Handle<Exception>()
.WaitAndRetryAsync(
retryCount: 2,
sleepDurationProvider:retryAttempt =>
TimeSpan.FromSeconds(Math.Pow (2, retryAttempt)),
onRetry: (exception, timeSpan, context) =>
{
var ex = (ApiException)exception;
//Do something with exception. Send to insights (now hockeyapp)
Debug.WriteLine($"Error: {ex.ReasonPhrase} |
TimeSpan: {timeSpan.Seconds}");
return;
}).ExecuteAsync(async() =>
await _eventService.GetEventsWithError());
}
return conferences;
}