12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Threading;
- using Lottomat.Application.Entity.CommonEntity;
- using Lottomat.Application.SystemAutoJob.Interface;
- using Lottomat.Utils.Date;
- namespace Lottomat.Application.SystemAutoJob
- {
- public class Scheduler
- {
- private readonly SchedulerConfiguration _configuration = null;
-
-
-
- private readonly List<int> _hour = new List<int>{ 0, 1, 2, 3, 4, 5 };
-
- private static readonly System.Timers.Timer _timer = new System.Timers.Timer();
-
-
-
-
- public Scheduler(SchedulerConfiguration config)
- {
- _configuration = config;
- }
-
-
-
- public void Start()
- {
- _timer.Start();
- _timer.Elapsed += new System.Timers.ElapsedEventHandler(ExecuteJob);
- _timer.Interval = 0.5 * 60 * 1000;
- _timer.Enabled = true;
- }
-
-
-
- private void ExecuteJob(object sender, EventArgs e)
- {
- DateTime now = DateTimeHelper.Now;
- if (!_hour.Contains(now.Hour))
- {
- List<TaskList> lists = _configuration._taskList;
- if (lists.Count != 0)
- {
- foreach (TaskList list in lists)
- {
-
- foreach (ISchedulerJob job in list.Jobs)
- {
- ThreadStart myThreadDelegate = new ThreadStart(job.Execute);
- Thread myThread = new Thread(myThreadDelegate)
- {
- IsBackground = true
- };
- myThread.Start();
- }
-
- Thread.Sleep(list.SleepInterval);
- }
- }
- }
- }
- }
- }
|