You can wrap the attempt as part of a method that handles the retry logic for you. For example, if you use WebClient async methods:
public async Task<T> RetryQuery<T>(Func<Task<T>> operation, int numberOfAttempts, int msecsBetweenRetries = 500) { while (numberOfAttempts > 0) { try { T value = await operation(); return value; } catch {
Then you can use this via:
// Try 3 times with 500 ms wait times in between string result = await RetryQuery(async () => webClient.DownloadStringTaskAsync(url), 3);
source share