How to debug the .NET Windows Service OnStart method?

后端 未结 16 1311
离开以前
离开以前 2020-12-01 00:13

I have code written in .NET that only fails when installed as a Windows service. The failure doesn\'t allow the service to even start. I can\'t figure out how I can step int

16条回答
  •  我在风中等你
    2020-12-01 00:24

    Use following Code in Service OnStart Method:

    System.Diagnostics.Debugger.Launch();
    

    Choose Visual Studio option from Pop Up message. Remember to run Visual Studio as Administrator.

    Note: To use it in only Debug mode, #if DEBUG compiler directive can be used, as follows. This will prevent accidental or Debugging in Release mode on Production server.

    #if DEBUG
        System.Diagnostics.Debugger.Launch();
    #endif
    

提交回复
热议问题