FarmMapsApiClient_WURtest/FarmmapsApi/Extensions.cs

27 lines
717 B
C#
Raw Normal View History

2020-03-25 10:39:26 +00:00
using System;
using System.Threading;
using System.Threading.Tasks;
2020-03-24 08:47:08 +00:00
namespace FarmmapsApi
{
public static class Extensions
{
2020-03-25 10:39:26 +00:00
public static async Task PollTask(TimeSpan retryTime, Func<CancellationTokenSource, Task> callback)
{
var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;
do
{
try
{
await callback(tokenSource);
await Task.Delay(retryTime, token);
}
catch
{
tokenSource.Cancel();
2020-03-25 10:39:26 +00:00
}
} while (!token.IsCancellationRequested);
2020-03-24 08:47:08 +00:00
}
}
}