using FastGithub.Scanner; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using System.Threading; using System.Threading.Tasks; namespace FastGithub { /// /// 扫描结果轮询扫描后台服务 /// sealed class GithubResultScanHostedService : BackgroundService { private readonly GithubScanService githubScanService; private readonly IOptionsMonitor options; /// /// 扫描结果轮询扫描后台服务 /// /// /// public GithubResultScanHostedService( GithubScanService githubScanService, IOptionsMonitor options) { this.githubScanService = githubScanService; this.options = options; } /// /// 后台轮询扫描 /// /// /// protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (stoppingToken.IsCancellationRequested == false) { await Task.Delay(this.options.CurrentValue.ResultScanInterval, stoppingToken); await githubScanService.ScanResultAsync(); } } } }