最近一直在用服务,发现服务也没有那么难调试。

Windows服务调试状态下用Console启动:步骤分两步

第一步改Program,启动代码

    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        static void Main(string[] args)
        {
            if (Environment.UserInteractive)
            {
                //交互模式下执行
                var test = new MyChatService();
                test.TestStartupAndStop(args);
            }
            else
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
                {
                new MyChatService()
                };
                ServiceBase.Run(ServicesToRun);
            }
        }
    }
MyChatService 为我的服务,TestStartupAndStop代码:在这个里面启动服务
        public void TestStartupAndStop(string[] args)
        {
            OnStart(args);
            Console.ReadLine();
            OnStop();
        }

 

第二步修改项目属性=》控制台应用程序

Windows服务调试状态下用Console启动

 

 ok,完成。

 

相关文章:

  • 2021-10-26
  • 2021-12-04
  • 2021-12-31
  • 2021-07-29
  • 2021-11-26
  • 2021-11-19
  • 2021-07-29
猜你喜欢
  • 2022-12-23
  • 2021-12-06
  • 2021-08-30
  • 2021-06-19
  • 2021-06-14
相关资源
相似解决方案