using System.Threading.Tasks;
public static async void Main()
var res1 = await CallAsyncMethodWithRetries(() => TestMethod("false"), 1, 1);
var res2 = await CallAsyncMethodWithRetries(() => TestMethod("true"), 1, 1);
Console.WriteLine("Result 1 = " + res1);
Console.WriteLine("Result 2 = " + res2);
private static async Task<bool> TestMethod(string arg) {
return await Task.Run(() => arg == "true");
private static async Task<bool> CallAsyncMethodWithRetries(
Func<Task<bool>> callback, int maxAttempts, int delay)
while (!await callback() && ++numOfTries < maxAttempts)
return numOfTries < maxAttempts;