Exemple #1
0
        /// <summary>
        /// Initializes the task manager with the property values specified in the configuration file.
        /// </summary>
        public void Initialize()
        {
            this._taskThreads.Clear();

            var taskService = DependencyResolver.Current.GetService<IScheduleTaskService>();
            var scheduleTasks = taskService.GetAll().OrderBy(x => x.Seconds).ToList();

            if (scheduleTasks.Count == 0) return;

            //group by threads with the same seconds
            foreach (var scheduleTaskGrouped in scheduleTasks.GroupBy(x => x.Seconds))
            {
                //create a thread
                var taskThread = new TaskThread();
                taskThread.Seconds = scheduleTaskGrouped.Key;
                this._taskThreads.Add(taskThread);
                foreach (var scheduleTask in scheduleTaskGrouped)
                {
                    Debug.WriteLine(string.Format("thread time:{0}:{1}",scheduleTask.Name, DateTime.Now));
                    var task = new Task(scheduleTask);
                    taskThread.AddTask(task);
                }
            }
            //one thread, one task
            //foreach (var scheduleTask in scheduleTasks)
            //{

            //    Debug.WriteLine(string.Format("thread time:{0}:{1}", scheduleTask.Name, DateTime.Now));
            //    var taskThread = new TaskThread(scheduleTask);
            //    this._taskThreads.Add(taskThread);
            //    var task = new Task(scheduleTask);
            //    taskThread.AddTask(task);
            //}
        }
Exemple #2
0
        /// <summary>
        /// Initializes the task manager with the property values specified in the configuration file.
        /// </summary>
        public void Initialize()
        {
            this._taskThreads.Clear();

            var taskService   = DependencyResolver.Current.GetService <IScheduleTaskService>();
            var scheduleTasks = taskService.GetAll().OrderBy(x => x.Seconds).ToList();

            if (scheduleTasks.Count == 0)
            {
                return;
            }

            //group by threads with the same seconds
            foreach (var scheduleTaskGrouped in scheduleTasks.GroupBy(x => x.Seconds))
            {
                //create a thread
                var taskThread = new TaskThread();
                taskThread.Seconds = scheduleTaskGrouped.Key;
                this._taskThreads.Add(taskThread);
                foreach (var scheduleTask in scheduleTaskGrouped)
                {
                    Debug.WriteLine(string.Format("thread time:{0}:{1}", scheduleTask.Name, DateTime.Now));
                    var task = new Task(scheduleTask);
                    taskThread.AddTask(task);
                }
            }
            //one thread, one task
            //foreach (var scheduleTask in scheduleTasks)
            //{

            //    Debug.WriteLine(string.Format("thread time:{0}:{1}", scheduleTask.Name, DateTime.Now));
            //    var taskThread = new TaskThread(scheduleTask);
            //    this._taskThreads.Add(taskThread);
            //    var task = new Task(scheduleTask);
            //    taskThread.AddTask(task);
            //}
        }