using System.Threading.Tasks;
static async Task Main(string[] args)
var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(5));
await RequestUtrn(10, cts.Token).WaitAsync(cts.Token);
catch (OperationCanceledException ex)
Console.WriteLine("Operation cancelled.");
static Task<string> RequestUtrn(int secondsDelay, CancellationToken cancellationToken)
while (iterations != secondsDelay)
cancellationToken.ThrowIfCancellationRequested();
Console.WriteLine($"....{iterations}");
Thread.Sleep(TimeSpan.FromSeconds(1));