private void InitialWithConfig(ProcessScheduleInfo SystemInfo)
        {
            if (SystemInfo != null)
            {
                _monitorWaitTime  = SystemInfo.Check_interval * 1000;
                this.waitDuration = SystemInfo.Run_interval;

                // 是否定时启动模式,
                // 1. 参数3 为HH:mm格式
                // 2. 参数4 为1(按天),2(按周),3(按月)之一
                // 3. 参数5 为整数
                string param3 = SystemInfo.System_parameter3;
                string param4 = SystemInfo.System_parameter4;
                string param5 = SystemInfo.System_parameter5;
                if (!string.IsNullOrEmpty(param3) &&
                    !string.IsNullOrEmpty(param4) &&
                    !string.IsNullOrEmpty(param5) &&
                    Regex.IsMatch(param3, "([0-1][0-9]|2[0-3]):([0-5][0-9])") &&
                    int.TryParse(param4, out _startbytimemode) &&
                    _startbytimemode > 0 && _startbytimemode < 4 &&
                    int.TryParse(param5, out _startParameter))
                {
                    _startbytime = true;
                    _starttime   = param3;
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="rdr"></param>
        /// <returns></returns>
        private static ProcessScheduleInfo CreateProcessScheduleInfo(IDataReader rdr)
        {
            ProcessScheduleInfo info = new ProcessScheduleInfo();

            info.System_name         = DBConvert.GetString(rdr, rdr.GetOrdinal("PROCESS_NAME"));
            info.Last_run_begin_time = DBConvert.GetDateTime(rdr, rdr.GetOrdinal("LAST_RUN_BEGIN_TIME"));
            info.Last_run_end_time   = DBConvert.GetDateTime(rdr, rdr.GetOrdinal("LAST_RUN_END_TIME"));
            info.Last_run_status     = DBConvert.GetInt32(rdr, rdr.GetOrdinal("LAST_RUN_STATUS"));
            info.Run_interval        = DBConvert.GetInt32(rdr, rdr.GetOrdinal("RUN_INTERVAL"));
            info.Check_interval      = DBConvert.GetInt32(rdr, rdr.GetOrdinal("CHECK_INTERVAL"));
            info.System_parameter1   = DBConvert.GetString(rdr, rdr.GetOrdinal("SYSTEM_PARAMETER1"));
            info.System_parameter2   = DBConvert.GetString(rdr, rdr.GetOrdinal("SYSTEM_PARAMETER2"));
            info.System_parameter3   = DBConvert.GetString(rdr, rdr.GetOrdinal("SYSTEM_PARAMETER3"));
            info.System_parameter4   = DBConvert.GetString(rdr, rdr.GetOrdinal("SYSTEM_PARAMETER4"));
            info.System_parameter5   = DBConvert.GetString(rdr, rdr.GetOrdinal("SYSTEM_PARAMETER5"));
            info.Service_fid         = DBConvert.GetGuid(rdr, rdr.GetOrdinal("FID"));
            return(info);
        }
        /// <summary>
        /// 监控线程,响应用户界面对工作线程的停止、启动操作
        /// </summary>
        protected void SystemMonitor()
        {
            Logger.Instance.Trace(this, "Entry SystemMonitor");
            //int index = 0;
            //
            // 系统监控线程将一直运行直到WindowsService被结束
            //
            while (isMonitorThreadActive)
            {
                //Infrustructure.Logger.Instance.Trace(this, string.Format("SystemMonitor loop {0}", (++index)));

                try
                {
                    //读取系统记录
                    ProcessScheduleInfo SystemInfo = ProcessScheduleDAL.GetInfo(_serviceFid);
                    InitialWithConfig(SystemInfo);
                    WorkInDuration(SystemInfo);
                }
                catch (Exception exception)
                {
                    Logger.Instance.Error(this, exception);
                    Logger.Instance.Info(this, "由于错误停止了工作线程");
                    #region Modify: Andy-Liu 2008-11-06 执行错误时,停止工作线程
                    //停止工作线程
                    if (isWorkThreadActive)
                    {
                        StopWorkThread();
                    }

                    #endregion
                }
                System.Threading.Thread.Sleep(_monitorWaitTime);
            }

            //如果监控线程被结束,那么工作线程也要结束
            if (isWorkThreadActive)
            {
                StopWorkThread();
            }
            Logger.Instance.Trace(this, "end SystemMonitor");
        }
        private void WorkInDuration(ProcessScheduleInfo SystemInfo)
        {
            if (SystemInfo != null)
            {
                ///正在运行过程中用户停止了线程
                if (SystemInfo.Last_run_status == ThreadStop && isWorkThreadActive)
                {
                    Logger.Instance.Trace(this, "should StopWorkThread");

                    //停止工作线程
                    StopWorkThread();
                }
                ///线程已经停止,用户启动线程
                if (SystemInfo.Last_run_status == ThreadActive && !isWorkThreadActive)
                {
                    Logger.Instance.Trace(this, "should StartWorkThread");

                    //启动工作线程
                    StartWorkThread();
                }
            }
        }