-
-
Save ChaseFlorell/9524b2e8a85dfa5b563e to your computer and use it in GitHub Desktop.
GetAsync with Retry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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