zoukankan      html  css  js  c++  java
  • 随笔——写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
            }
  • 相关阅读:
    「模拟赛20180306」回忆树 memory LCA+KMP+AC自动机+树状数组
    python写一个通讯录
    Git学习笔记
    交换排序
    用Windows自带的方法创建WiFi
    MySQL之触发器
    插入排序
    range和arange的区别
    Spring前后端跨域请求设置
    三、图的定义及遍历
  • 原文地址:https://www.cnblogs.com/bklsj/p/13921030.html
Copyright © 2011-2022 走看看