public static void StopRunning() { _cancelationTokenSource.Cancel(); ThreadDelayer.WaitSomeTime(); _logger.Information("Canceled the token on runner."); WebDriverProvider.CloseWebDriver(); _logger.Information("Closed web driver"); }
public static Task RunBotForTagsAsync(IEnumerable <Tag> tags, ILogger logger) { _logger = logger; lock (_lockObject) { if (_botRunningTask == null || _botRunningTask.IsCompleted) { _botRunningTask = new Task(() => RunBotForTags(tags, _cancelationTokenSource.Token)); _botRunningTask.Start(); _botRunningTask.ContinueWith(task => WebDriverProvider.CloseWebDriver(), TaskScheduler.Current); return(_botRunningTask); } else { _logger.Error("The bot runner cannot be started because the previous bot running task was not completed."); throw new Exception("cannot start another task because the current one is not completed."); } } }