internal bool Remove(NotifySchedule schedule) { lock (_lock) { return(_schedules.Remove(schedule)); } }
internal void Add(NotifySchedule schedule) { lock (_lock) { _schedules.Add(schedule); } }
public NotifySchedule NotifySchedule(NotifySchedule schedule) { lock (((ICollection)NotifySchedules).SyncRoot) { NotifySchedules.Add(schedule); } return(schedule); }
public static void AddJob(NotifySchedule schedule, Action <NotifySchedule> jobSchedule) { if (schedule == null) { throw new ArgumentNullException("schedule"); } if (jobSchedule == null) { throw new ArgumentNullException("jobSchedule"); } AddJob(jobSchedule, schedule); }
public NotifySchedule NotifySchedule(Action action, string name) { var schedule = new NotifySchedule(action); if (_allJobsConfiguredAsNonReentrant) { schedule.NonReentrant(); } lock (((ICollection)NotifySchedules).SyncRoot) { NotifySchedules.Add(schedule); } schedule.Name = name; return(schedule); }
public static void SendNotify(NotifySchedule schedule) { lock (_running) { if (schedule.Reentrant != null && _running.Any(t => ReferenceEquals(t.Item1.Reentrant, schedule.Reentrant))) { return; } } Tuple <NotifySchedule, Task> tuple = null; var task = new Task(() => { var start = Now; if (JobStart != null) { Task.Factory.StartNew(() => { JobStart( new JobStartInfo { Name = schedule.Name, StartTime = start, } ); }, TaskCreationOptions.PreferFairness); } var stopwatch = new Stopwatch(); try { stopwatch.Start(); schedule.Notifies.ForEach(action => Task.Factory.StartNew(action, TaskCreationOptions.AttachedToParent).Wait()); //schedule.Notifies.ForEach(action => action()); } catch (Exception e) { if (JobException != null) { JobException( new JobExceptionInfo { Name = schedule.Name, Exception = e, } ); } } finally { lock (_running) { _running.Remove(tuple); } if (JobEnd != null) { Task.Factory.StartNew(() => { JobEnd( new JobEndInfo { Name = schedule.Name, StartTime = start, Duration = stopwatch.Elapsed, NextRun = schedule.NextRun, } ); }, TaskCreationOptions.PreferFairness); } } }, TaskCreationOptions.PreferFairness); tuple = new Tuple <NotifySchedule, Task>(schedule, task); lock (_running) { _running.Add(tuple); } task.Start(); }
private static void AddJob(Action <NotifySchedule> jobSchedule, NotifySchedule schedule) { jobSchedule(schedule); CalculateNextRun(new NotifySchedule[] { schedule }).ToList().ForEach(SendNotify); ScheduleJobs(); }