Exemple #1
0
        /// <summary>
        /// 记录任务最后一次执行的时间
        /// </summary>
        /// <param name="taskType"></param>
        /// <param name="time"></param>
        private static void RecordExecuteTime(string taskType, DateTime time)
        {
            try
            {
                TaskConfigInfo task = TaskConfigs.Instance().GetConfig().FindConfig(taskType);
                //设置最后一次执行时间

                /*if (task.Timetype == TaskTimeType.Day)
                 * {
                 *
                 *  task.LastExecuteTime = task.LastExecuteTime.AddDays(task.Interval);
                 * }
                 * else
                 * {
                 *
                 *  task.LastExecuteTime = DateTime.Now;
                 * }*/

                task.LastExecuteTime = DateTime.Now;
                TaskConfigs.Instance().Save(TaskConfigs.Instance().GetConfig());
            }
            catch (Exception ex)
            {
                //Log4Helper.Error(ex.Message);
            }
        }
Exemple #2
0
        /// <summary>
        /// 初始化加载所有任务
        /// </summary>
        public static void Init()
        {
            if (_allTasks.Count <= 0)
            {
                List <TaskConfigInfo> configList = TaskConfigs.Instance().GetConfig().ConfigList;
                //Log4Helper.Info(configList.Count + "个任务将被执行,等待执行中...");
                Cms.Common.FileHelper.Write("E:\\win_services\\DBE\\log.txt", configList.Count + "个任务将被执行,等待执行中...");
                foreach (TaskConfigInfo taskConfig in configList)
                {
                    Type type = Type.GetType(taskConfig.TypeName);
                    if (type == null)
                    {
                        //Log4Helper.Error(string.Format("任务 {0} 无法被正确识别", taskConfig.TypeName));
                    }
                    else
                    {
                        TaskBase taskbase = (TaskBase)Activator.CreateInstance(type);
                        taskbase.Init(taskConfig);
                        if (taskbase == null)
                        {
                            //Log4Helper.Error(string.Format("任务 {0} 无法被正确加载", taskConfig.TypeName));
                        }
                        else
                        {
                            _allTasks.Add(taskbase);
                        }
                    }
                }
            }

            StartTaskThread();
        }