private async void ScheduleNext()
 {
     try
     {
         await Task
         .Run(async() => await _service.PeriodicActionAsync(_cancellationToken), _cancellationToken)
         .ConfigureAwait(false);
     }
     catch (Exception e)
     {
         Log.Error(_service.Name, e.ToString());
     }
     _handler.PostDelayed(ScheduleNext, (long)_period.TotalMilliseconds);
 }
コード例 #2
0
        private async Task PeriodicTaskWrapper(IPeriodicService service, TimeSpan period, CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                try
                {
                    await Task.Delay(period, cancellationToken);

                    await service.PeriodicActionAsync(cancellationToken);
                }
                catch (OperationCanceledException)
                {
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }
        }