How to debug the .NET Windows Service OnStart method?

后端 未结 16 1308
离开以前
离开以前 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:36

    You can add a line of code like this:

    System.Diagnostics.Debugger.Break()
    

    which will bring up a window prompting you to choose which debugger to use to debug, e.g. allowing you to attach with Visual Studio and step into the code.

    see:

    http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx

提交回复
热议问题