/// <summary> /// 文件改动事件 /// </summary> /// <param name="source"></param> /// <param name="e"></param> private void OnChanged(object source, FileSystemEventArgs e) { var jobList = (List <JobDetail>)XmlHelper.XmlDeserialize(typeof(List <JobDetail>), Config.ConfigPath); if (jobList != null) { foreach (var item in jobList) { if (dicTimer.Any(o => o.Key == item.Name)) { var timer = dicTimer[item.Name]; if (item.JobType != timer.JobDetail.JobType || item.CronExpression != timer.JobDetail.CronExpression) { timer.JobDetail = CronHelper.SetCron(item); if (timer.JobDetail.WorkType == WorkType.Loop) { timer.Interval = timer.JobDetail.Interval; } else { timer.Interval = 1000; } } timer.JobDetail.Enabled = item.Enabled; timer.JobDetail.StartTime = item.StartTime; timer.JobDetail.EndTime = item.EndTime; } else { SetTimer(item); } } } }
/// <summary> /// Timer /// </summary> /// <param name="jobDetail"></param> private void SetTimer(JobDetail jobDetail) { TWTimer timer = new TWTimer(); timer.JobDetail = CronHelper.SetCron(jobDetail); if (timer.JobDetail.WorkType == WorkType.Loop) { timer.Interval = timer.JobDetail.Interval; } else { timer.Interval = 1000; } timer.AutoReset = true; timer.Enabled = true; timer.Elapsed += new ElapsedEventHandler(OnTimedEvent); dicTimer.Add(timer.JobDetail.Name, timer); }