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
    
        }
      }
    }
    复制代码
  • 相关阅读:
    paip.提高开发效率自动数据库SQL备份
    paip.提升开发效率增量备份项目文件
    paip.提升开发效率使用拼音
    paip.asp vbs代码的排版格式化
    paip.asp vbs的代码折叠代码结构查看
    paip.提升用户体验文件查找
    poj3026
    poj3020
    poj1182
    POJ典型算法例题题号
  • 原文地址:https://www.cnblogs.com/BoKeYuan259/p/15508476.html
Copyright © 2011-2022 走看看