示例#1
0
        protected override async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            try
            {
                if (settings.Value.ScanInterval == default)
                {
                    throw new ArgumentException("ScanInterval must not be zero");
                }

                while (!cancellationToken.IsCancellationRequested)
                {
                    await sampler.Execute();

                    try
                    {
                        await Task.Delay(settings.Value.ScanInterval, cancellationToken);
                    }
                    catch (TaskCanceledException)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogCritical(ex, "A fatal error has occurred");
                throw;
            }
        }