软件编程
位置:首页>> 软件编程>> C#编程>> 使用windows控制台调试服务的方法

使用windows控制台调试服务的方法

  发布时间:2023-08-19 03:34:30 

标签:windows,控制台,服务

将Program类的删除,将里面的静态类Main修改后放入服务类中:


partial class Server1 : ServiceBase
    {       
        public Server1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        static void Main(string[] args)
        {

            Server1 sv = new Server1();
            if (args.Length > 0)
            {
                sv.OnStart(args);
                char c;
                while ((c = Convert.ToChar(Console.Read())) != 'q')
                    if (c == 'g') GC.Collect();
                sv.OnStop();
                Console.ReadLine();
            }
            else
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
            {
                sv
            };
                ServiceBase.Run(ServicesToRun);
            }
        }
        protected override void OnStart(string[] args)
        {

        }
        protected override void OnStop()
        {

        }
    }

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com