protected override async Task ExecuteAsync(CancellationToken stoppingToken) { var th = new System.Threading.Thread(async() => { WorkerLog.Instance.Information($"Starting {nameof(FileCollectorWorker)}"); while (!stoppingToken.IsCancellationRequested) { var queryResult = await _folderRespository.GetFoldersToCrawl(); if (queryResult.WasSuccessful) { foreach (var folder in queryResult.Data) { try { WorkerLog.Instance.Information($"Crawling through folder '{folder.Name}'"); var collector = _fileCollectorFactory.Get(folder); await collector.CollectFiles(); await ProcessNewFiles(folder, collector.NewFiles); await ProcessChangedFiles(folder, collector.ChangedFiles); } catch (Exception ex) { WorkerLog.Instance.Error(ex, $"Unexpected error occured during processing of folder {folder.Name}"); } } } WorkerLog.Instance.Information($"Waiting {TimeSpan.FromMinutes(_triggerInterval)}min for next cycle of foldercrawling"); await Task.Delay(TimeSpan.FromMinutes(_triggerInterval)); } }); th.Start(); await Task.Delay(Timeout.Infinite); }