zoukankan      html  css  js  c++  java
  • debug 调试Windows service服务调试

    Service1.cs

    复制代码
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    
    namespace WindowsService1
    {
      public partial class Service1 : ServiceBase
      {
        public Service1()
        {
          InitializeComponent();
        }
    
        public void OnDebug()
        {
          string[] str = { "0" };
          OnStart(str);
        }
    
        protected override void OnStart(string[] args)
        {
          File.Create(AppDomain.CurrentDomain.BaseDirectory + "OnStart.txt");
        }
    
        protected override void OnStop()
        {
          File.Create(AppDomain.CurrentDomain.BaseDirectory + "OnStop.txt");
        }
    
      }
    }
    复制代码

    Program.cs

    复制代码
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace WindowsService1
    {
      static class Program
      {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
    #if DEBUG  
          Console.WriteLine("This is debug mode");
          Service1 myService = new Service1();
          myService.OnDebug();
    #else
          ServiceBase[] ServicesToRun;
          ServicesToRun = new ServiceBase[]
          {
                    new Service1()
          };
          ServiceBase.Run(ServicesToRun);
    #endif
    
        }
      }
    }
    复制代码
  • 相关阅读:
    js截取字符串区分汉字字母代码
    List 去处自定义重复对象方法
    63. Unique Paths II
    62. Unique Paths
    388. Longest Absolute File Path
    41. First Missing Positive
    140. Word Break II
    139. Word Break
    239. Sliding Window Maximum
    5. Longest Palindromic Substring
  • 原文地址:https://www.cnblogs.com/BoKeYuan259/p/15508476.html
Copyright © 2011-2022 走看看