zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    系统集成项目管理工程师计算题(成本管理计算)
    系统集成项目管理工程师计算题(进度管理计算)
    系统集成项目管理工程师计算题(期望值)
    系统集成项目管理工程师计算题(三点估算)
    系统集成项目管理工程师计算题(沟通渠道)
    Asp.net core web Api 应用Jwt 验证
    Linux vmstat命令
    关于Java集合的小抄
    @Resource和@Autowire
    Servlet是线程安全的吗?
  • 原文地址:https://www.cnblogs.com/hack1506/p/1897616.html
Copyright © 2011-2022 走看看