protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { try { await semaphore.WaitAsync(stoppingToken); logger.LogInformation("Running background update."); var updateTask = new CrawlTask(connectionFactory, client, 1); await updateTask.Run(stoppingToken); logger.LogInformation("Update finished. Clearing cache."); cacheManager.Clear(); logger.LogInformation("Background update completed successfully."); } catch (Exception ex) { logger.LogError(ex, "Background update failed due to error."); } finally { semaphore.Release(); } await Task.Delay(TimeSpan.FromMinutes(minutesBetweenRun), stoppingToken); } }
public static async Task Main(string[] args) { Trace.Listeners.Add(MyConsoleListener.Instance); var connectionFactory = new MyConnectionFactory(@"C:\git\csharp\hn-reader\data\hn-data.sqlite"); var crawlTask = new CrawlTask(connectionFactory, Client, 3); await crawlTask.Run(); }
public static async Task Main(string[] args) { Trace.Listeners.Add(MyConsoleListener.Instance); using (var connection = Connector.ConnectToFile(@"C:\git\csharp\hn-reader\data\hn-data.sqlite")) { var crawlTask = new CrawlTask(connection, Client, 3); await crawlTask.Run(); } }