Beispiel #1
0
        /// <summary>
        /// 执行任务
        /// </summary>
        public void Execute()
        {
            while (true)
            {
                if (this.IsRun() && this._State == JobState.Running)
                {
                    //记录最近执行时间
                    _LatestRunTime = DateTime.Now.ToString();

                    try
                    {
                        WriteLog(string.Format("正在执行任务[{0}]......", this.Name), LogType.Information);

                        //执行任务
                        Type   type = Type.GetType(string.Format("{0}, {1}", _ClassName, _AssemblyName));
                        object obj  = Activator.CreateInstance(type);
                        ITask  task = obj as ITask;
                        task.Run();

                        WriteLog(string.Format("执行任务[{0}]成功!", this.Name), LogType.Information);
                    }
                    catch (Exception ex)
                    {
                        if (_IsStopIfException)
                        {
                            _State = JobState.Stop;
                            TaskThreadPool.Instance.Threads[_Name].Abort();
                        }

                        _ExceptionCount  = _ExceptionCount + 1;
                        _LatestException = new MySoftException(ExceptionType.TaskException, "Task任务执行失败!", ex);

                        WriteLog(string.Format("执行任务[{0}]失败,错误:{1}!", this.Name, ex.Message), LogType.Error);
                    }
                }

                Thread.Sleep(_Interval);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 执行任务
        /// </summary>
        public void Execute()
        {
            while (true)
            {
                if (this.IsRun() && this._State == JobState.Running)
                {
                    //记录最近执行时间
                    _LatestRunTime = DateTime.Now.ToString();

                    try
                    {
                        WriteLog(string.Format("正在执行任务[{0}]......", this.Name), LogType.Information);

                        //执行任务
                        Type type = Type.GetType(string.Format("{0}, {1}", _ClassName, _AssemblyName));
                        object obj = Activator.CreateInstance(type);
                        ITask task = obj as ITask;
                        task.Run();

                        WriteLog(string.Format("执行任务[{0}]成功!", this.Name), LogType.Information);
                    }
                    catch (Exception ex)
                    {
                        if (_IsStopIfException)
                        {
                            _State = JobState.Stop;
                            TaskThreadPool.Instance.Threads[_Name].Abort();
                        }

                        _ExceptionCount = _ExceptionCount + 1;
                        _LatestException = new MySoftException(ExceptionType.TaskException, "Task任务执行失败!", ex);

                        WriteLog(string.Format("执行任务[{0}]失败,错误:{1}!", this.Name, ex.Message), LogType.Error);
                    }
                }

                Thread.Sleep(_Interval);
            }
        }