public JobScheduler(Action <JobSchedulerConfiguration> config) { _config = new JobSchedulerConfiguration(); _timersDict = new DisposableConcurrentDictionary <Type, JobTimer>(); config.Invoke(_config); }
private JobTimer(Type jobType, string cronExpression, JobSchedulerConfiguration config) { _config = config; _cronWrapper = new CronExpressionWrapper(cronExpression, _config.IsUsingUtcTime); _timer = new Timer((callback) => { var job = Activator.CreateInstance((Type)callback) as IScheduledJob; _cancellationToken = new JobCancellationTokenSource(); Task.Factory.StartNew(() => ExecuteJob(job, _cancellationToken.Token), _cancellationToken.Token, TaskCreationOptions.LongRunning, new TaskScheduler()) .ContinueWith(task => HandleTaskAfter(task, jobType.Name)); }, jobType, (long)_cronWrapper.GetStartTime().TotalMilliseconds, (long)_cronWrapper.GetNextStartTime().TotalMilliseconds); }
public static JobTimer New <TJob>(string cronExpression, JobSchedulerConfiguration config) where TJob : IScheduledJob { return(new JobTimer(typeof(TJob), cronExpression, config)); }