How about:
private const int TotalNumberOfAttempts = 10;
public static async Task<HttpResponseMessage> PutWithRetriesAsync(string url,
HttpContent content,
AuthenticationHeaderValue authenticationHeaderValue,
MediaTypeWithQualityHeaderValue mediaTypeWithQualityHeaderValue)
{
var exceptions = new List<Exceptions>List<Exception>();
for(int i = 0; i < TotalNumberOfAttempts; i++)
{
try
{
return await PutAsync(url, content, authenticationHeaderValue, mediaTypeWithQualityHeaderValue);
}
catch (AggregateException ex)
{
exceptions.Add(ex);
}
}
throw new AggregateException(exceptions);
}
You can easily abstract this functionality into an extension method to provide retry logic for any arbitrary Func<Task>.