• window服务程序编写及发布


    log4net打印log日志必须在AssemblyInfo.cs里面增加[assembly: log4net.Config.DOMConfigurator(Watch = true)]

    windows主窗体运行程序

      private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
      
           
           
            string updateTime = string.Empty;

            /// <summary>
            /// 上一次执行时间

            /// </summary>
            DateTime NewUpTime=System.DateTime.Now;
            public NewOrientalDataCenterService()
            {
                log.Info("-------------------------日志开始输出------------------------");
                InitializeComponent();
              
              
            }

            protected override void OnStart(string[] args)
            {

               
                MyTime.Interval = 1000;
                MyTime.Start();
            }

            protected override void OnStop()
            {
              
                MyTime.Stop();
                MyTime.Dispose();

            }
            
            private void StartGetData()
            {
                DayGetData getdata = new DayGetData();
                getdata.GetAllData();
                if (Config.IsCheck)
                {
                    RefreshTableInfo f=new RefreshTableInfo();
                    f.Refresh();
                }
                log.Info("-------------------------此次数据已经同步完成------------------------");
              
            }

            private void TimerEventProcessor(object sender, System.Timers.ElapsedEventArgs e)
            {


                if (!Config.IsOpen)
                {
                    string tim = System.DateTime.Now.ToString("H:mm");
                    if (Config.firstTime == tim || Config.SecondTime == tim || Config.ThirdTime == tim || Config.FourthTime == tim)
                    {
                        if (tim != updateTime)
                        {
                            MyTime.Enabled = false;
                            StartGetData();
                            MyTime.Enabled = true;
                            updateTime = tim;
                        }
                    }
                }
                else {
                  
                    System.TimeSpan ND = System.DateTime.Now - NewUpTime;
                    if (ND.TotalMinutes >= Config.OpenTime)
                    {
                        log.Info("---------------- System.TimeSpan ND = System.DateTime.Now - NewUpTime;" + (System.DateTime.Now - NewUpTime) + "--------------");
                        MyTime.Enabled = false;
                        StartGetData();
                        MyTime.Enabled = true;
                        NewUpTime = System.DateTime.Now;
                    }
                }
               
            }s

    窗体中增加计时器

     private Timer MyTime;
            /// <summary>
            /// 必需的设计器变量。

            /// </summary>
            private System.ComponentModel.IContainer components = null;

            /// <summary>
            /// 清理所有正在使用的资源。

            /// </summary>
            /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }

            #region 组件设计器生成的代码

            /// <summary>
            /// 设计器支持所需的方法 - 不要
            /// 使用代码编辑器修改此方法的内容。

            /// </summary>
            private void InitializeComponent()
            {
                this.MyTime = new System.Timers.Timer();
                ((System.ComponentModel.ISupportInitialize)(this.MyTime)).BeginInit();
                //
                // MyTime
                //
                this.MyTime.Elapsed += new System.Timers.ElapsedEventHandler(this.TimerEventProcessor);
                //
                // NewOrientalDataCenterService
                //
                this.ServiceName = "NewOrientalDataCenterService";
                ((System.ComponentModel.ISupportInitialize)(this.MyTime)).EndInit();

            }s

  • 相关阅读:
    查找目录中同名的文件或者文件夹
    「JOISC 2014 Day1」历史研究 --- 回滚莫队
    CSP2019 —— 今年欢笑复明年,不知退役在眼前
    C++实现,拓展中国剩余定理——解同余方程组(理论证明和代码实现)
    [SDOI2016]征途 —— 斜率优化DP
    codeforces#1215E. Marbles(状压DP)
    浅谈矩阵加速——以时间复杂度为O(log n)的算法实现裴波那契数列第n项及前n之和使用矩阵加速法的优化求法
    C++[Tarjan求点双连通分量,割点][HNOI2012]矿场搭建
    浅谈数学上的矩阵——矩阵的乘法运算的概念及C++上的实现模板
    C++边双缩点,Redundant Paths 分离的路径
  • 原文地址:https://www.cnblogs.com/hack1506/p/1897616.html
Copyright © 2020-2023  润新知