• 随笔——写windows服务的时候如何调试 c# .net


    流程

    1、更改项目 应用程序——输出类型——windows应用程序 改为 控制台应用程序

    2、Program启动类中添加调用代码

    3、服务类里面添加启动方法去启动OnStart和 Console.ReadLine();停止OnStop方法。

    操作

    1、更改项目

     2、Program添加代码

      /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            static void Main()
            {
    #if DEBUG
                //调试的时候记得把 应用程序——输出类型——windows应用程序 改为 控制台应用程序
                if (Environment.UserInteractive)
                {
                    Service1 service1 = new Service1();
                    service1.TestStartupAndStop();
                }
    #endif
    #if !DEBUG
    //下面这块是调用服务的,创建服务自动生成的
    ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1() }; ServiceBase.Run(ServicesToRun); #endif }

    3、服务类里面添加方法调用start和stop

         /// <summary>
            /// 添加个内部方法,用于调试
            /// </summary>
            /// <param name="args"></param>
            internal void TestStartupAndStop()
            {
    #if DEBUG
                this.OnStart(new string[0]);
                Console.ReadLine();
                this.OnStop();
    #endif
            }
  • 相关阅读:
    第一行DOCTYPE 的作用
    es6 proxy、handler.get()
    vue router-link 默认a标签去除下划线
    打开记事本
    JS数组遍历的方法
    vue项目中使用proxy解决跨域
    封装axios
    postMessage vue iframe传值
    input限制只能输入数字,且保留小数后两位
    axios封装
  • 原文地址:https://www.cnblogs.com/bklsj/p/13921030.html
Copyright © 2020-2023  润新知