-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskUtility.cs
37 lines (34 loc) · 1.01 KB
/
TaskUtility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace OrleansContrib.ActivationShedding
{
internal static class TaskUtility
{
internal static async Task RepeatEvery(Func<Task> func,
TimeSpan interval, CancellationToken cancellationToken, ILogger<ActivationSheddingFilter> logger)
{
while (!cancellationToken.IsCancellationRequested)
{
try
{
await func();
}
catch (Exception ex)
{
logger.LogError(ex, "TaskUtility.RepeatEvery task failed: {ErrorMessage}", ex.Message);
}
Task task = Task.Delay(interval, cancellationToken);
try
{
await task;
}
catch (TaskCanceledException)
{
return;
}
}
}
}
}