zoukankan      html  css  js  c++  java
  • windows 服务(可以控制台调试)

    using System;
    using System.Collections.Generic;

    using System.ServiceProcess;
    using System.Text;

    namespace NeoSuiteCIMS_FW
    {
        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            static void Main()
            {
                string sw = AppConfig.GetConfig("switch");
                //启动服务
                if (!string.IsNullOrEmpty(sw) && sw == "1")
                {
                    ServiceBase[] ServicesToRun;
                    ServicesToRun = new ServiceBase[]
                    {
                        new Service1()
                    };
                    ServiceBase.Run(ServicesToRun);
                }
                else
                {
                    //存储过程的名字
                    string proName = "p_result";
                    //控制台调试
                    ServiceConsole.Execute(proName);
                }

            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.ServiceProcess;
    using System.Text;
    using System.Timers;
    using System.IO;
    using System.Text.RegularExpressions;

    namespace NeoSuiteCIMS_FW
    {
        public partial class Service1 : ServiceBase
        {
            Timer timer1 = new Timer();
            int timeout = Convert.ToInt32(AppConfig.GetConfig("timeout"));
            public Service1()
            {
                InitializeComponent();

                //每天24点执行服务,如果第一次启动服务的时间不是24点,计算时间间隔
                if (DateTime.Now.Hour != 0)
                {
                    //DateTime nextDay = DateTime.Now.AddDa=ys(1).Date;
                    DateTime nextDay = DateTime.Now.AddMinutes(timeout);
                    TimeSpan ts = nextDay - DateTime.Now;
                    timer1.Interval = Convert.ToInt32(ts.TotalMilliseconds);
                }
                timer1.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
                timer1.Enabled = true;
            }

            protected override void OnStart(string[] args)
            {
                timer1.Start();
                LogHelper.Info("服务启动:" + DateTime.Now.ToString());
            }

            protected override void OnStop()
            {
                timer1.Stop();
                LogHelper.Info("服务停止:" + DateTime.Now.ToString());
            }

            private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                try
                {
                    //存储过程的名字
                    string proName = "p_result";
                    ServiceConsole.Execute(proName);
                }
                catch (Exception ex)
                {
                    LogHelper.Error("服务执行中出错:" + ex.Message);
                }
            }
        }
    }

  • 相关阅读:
    如何生产兼容性强的自动化测试脚本
    微信小程序和小游戏自动化测试
    如何测试Windows应用程序
    如何在iOS手机上进行自动化测试
    如何在Android手机上进行自动化测试(下)
    如何在Android手机上进行自动化测试(上)
    Poco的介绍和入门教学
    Airtest介绍与脚本入门
    5分钟上手自动化测试——Airtest+Poco快速上手
    Coursera课程笔记----计算导论与C语言基础----Week 4
  • 原文地址:https://www.cnblogs.com/wenbing/p/3605190.html
Copyright © 2011-2022 走看看