首页| JavaScript| HTML/CSS| Matlab| PHP| Python| Java| C/C++/VC++| C#| ASP| 其他|
购买积分 购买会员 激活码充值

您现在的位置是:虫虫源码 > C# > C#自动更新服务(本地服务安装)

C#自动更新服务(本地服务安装)

  • 资源大小:1.21M
  • 上传时间:2021-07-21
  • 下载次数:0次
  • 浏览次数:0次
  • 资源积分:1积分
  • 标      签: Windows系统编程

资 源 简 介

using System;using System.Collections.Generic;using System.Linq;using System.Text;using Common.WinService;using Common.Log;using System.Threading;using Common.Net;using System.Text.RegularExpressions;namespace Collection.AutoRunner{    //获取学生信息    public class Service_Update_Data : IWindowsService    {        private ILogWriter _logWriter = null;        private const string logCategory = "Services.Info";        private string logInfoSource = "Update_Data";        private const string logErrorCategory = "Services.Error";        private const string logErrorSource = "Update_Data_Error";        private bool BeStop = true;        private System.Timers.Timer timer = null;        public void Start(Common.Log.ILogWriter logWriter, string gameCode)        {            gameCode = gameCode.ToUpper();            logInfoSource = gameCode;            _logWriter = logWriter;            BeStop = false;            StartRequestData();        }        int stata = 0;        private void StartRequestData()        {            try            {                #region 配置                //时间频率                var UpdateStudentSpan = ServiceHelper.GetInterval("UpdateData");                //更新学生开始时间                var studentbegintime = ServiceHelper.GetInterval("StudentBeginTime");                //更新学生结束时间                var studentendtime = ServiceHelper.GetInterval("StudentEndTime");                    //是否更新学生基本信息:true为更新 false为不更新                var IsUpdateStudnet =Convert.ToBoolean(ServiceHelper.GetSystemConfig("IsUpdateStudnet"));                                #endregion                timer = ServiceHelper.ExcuteByTimer(UpdateStudentSpan, () =>                {                    int timeHour = DateTime.Now.Hour;                    if (timeHour == 3)                        stata = 0;                    #region 更新学生基本信息                    if (studentbegintime <= timeHour && timeHour < studentendtime && stata == 0 && IsUpdateStudnet)                    {                        stata = 1;                        StudentInfo();                    }                    else                    {                        this.WriteLog("还未到获取学生基本信息的时间段内... ");                    }                    #endregion                          StartRequestData();                });            }            catch (Exception ex)            {                this.WriteLog("获取学生信息数据出错 - " ex.Message);            }        }        private void StudentInfo()        {            int repeatTimes = 0;            try            {                this.WriteLog("开始获取学生信息数据....");                      this.WriteLog("学生信息数据获取完成....");            }            catch (Exception ex)            {                this.WriteLog("获取学生信息数据出错 - DoWork -" ex.Message);                if (repeatTimes == 0)                {                    repeatTimes ;                    StudentInfo();                }            }        }        public void Stop()        {            BeStop = true;            if (timer != null)                timer.Stop();        }        public void WriteError(string log)        {            _logWriter.Write(logErrorCategory, logErrorSource, LogType.Error, "自动获取学生信息数据异常", log);        }        public void WriteLog(string log)        {            _logWriter.Write(logCategory, logInfoSource, LogType.Information, "自动获取学生信息数据", log);        }    }}
VIP VIP
0.163807s