using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Http;
public static void Main()
var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;
Console.WriteLine("Start");
var process1Task = Process1Async();
Task<string> process2Task = Task<string>.Factory.StartNew(async ()=> await Process2());
bool process1MessageShown = false;
bool process2MessageShown = true;
Console.WriteLine(process2Task.Result);process2MessageShown=true;
Console.WriteLine(process1Task.Result);process1MessageShown=true;
public static async Task<string> Process1Async(){
var maxRetryAttempts = 10;
var pauseBetweenFailures = TimeSpan.FromSeconds(2);
i => pauseBetweenFailures,
(exception, timeSpan, retryCount, context) => ManageRetryException(exception, timeSpan, retryCount, context));
var timeOutPolicy = Policy
TimeoutStrategy.Pessimistic,
(context, timeSpan, task) => ManageTimeoutException(context, timeSpan, task));
var policyWrap = Policy.WrapAsync(retryPolicy, timeOutPolicy);
HttpClient client = new HttpClient();
Task<string> getStringTask = client.GetStringAsync("https:/google.com");
string urlContents = await getStringTask;
public static int Process2(){