Skip to content

Instantly share code, notes, and snippets.

@ChaseFlorell
Created August 13, 2014 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChaseFlorell/9524b2e8a85dfa5b563e to your computer and use it in GitHub Desktop.
Save ChaseFlorell/9524b2e8a85dfa5b563e to your computer and use it in GitHub Desktop.
GetAsync with Retry
public static async Task<HttpResponseMessage> GetWithRetriesAsync(string url,
AuthenticationHeaderValue authenticationHeaderValue,
MediaTypeWithQualityHeaderValue mediaTypeWithQualityHeaderValue)
{
var numberOfAttempts = 0;
AggregateException capturedException;
do
{
try
{
return await GetAsync(url, authenticationHeaderValue, mediaTypeWithQualityHeaderValue);
}
catch (AggregateException ex)
{
numberOfAttempts++;
capturedException = ex;
}
} while (numberOfAttempts < TotalNumberOfAttempts);
throw capturedException;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment