namespace Connected.Hosting.Workers { public abstract class ScheduledWorker : Worker { protected virtual TimeSpan Timer { get; set; } = TimeSpan.FromMinutes(1); protected long Count { get; private set; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { do { try { await OnInvoke(stoppingToken); } catch (Exception ex) { await OnError(ex); } finally { Count++; } if (Timer == TimeSpan.Zero) break; await Task.Delay(Timer, stoppingToken); } while (!stoppingToken.IsCancellationRequested); } } }