private void ShedulerThread(SchedulerParams schdlrParams) { try { _isRunning = true; _state = ESchedulerState.Init; while (_isRunning) { _state = ESchedulerState.RunningJobs; RunJobs(schdlrParams); _state = ESchedulerState.Delay; Thread.Sleep(schdlrParams.SleepDelay * 1000); } } catch (Exception ex) { _logger.Log(EErrorType.Error, "Failed to start scheduler"); _logger.Log(ex); } _state = ESchedulerState.Idle; }
public void StopJob() { State = ESchedulerState.Stopping; if (_job != null) { _job.IsRunning = false; } if (!_timer?.Enabled == false) { State = ESchedulerState.Stopped; } }
public void StartJob(string jobId, SmtpConfig cfg) { _smtpCfg = cfg; _mailer = new SmartMailer(); _mailer.Configure(_smtpCfg); if (_job != null) { StopJob(); } _mailToSend = _appSvc.GetMailCorrente(); var timeout = DateTime.Now.AddSeconds(15); while (_timer != null && _timer.Enabled) { if (timeout <= DateTime.Now) { break; } Thread.Sleep(200); } _timer?.Dispose(); _timer = null; try { _job = new JobDescriptor() { JobId = jobId, IsRunning = true }; _timer = new Timer(DELTA); _timer.Elapsed += (sender, e) => OnTimedEvent(sender, e, this); _timer.Start(); State = ESchedulerState.Running; } catch (Exception exc) { State = ESchedulerState.Stopped; _timer?.Dispose(); _timer = null; throw; } }
public Scheduler() { _isRunning = false; _state = ESchedulerState.Idle; _logger = Global.Logger; }