Wrapping a C# service in a console app to debug it

前端 未结 10 1210
遇见更好的自我
遇见更好的自我 2020-12-15 03:36

I want to debug a service written in C# and the old fashioned way is just too long. I have to stop the service, start my application that uses the service in debug mode (Vis

10条回答
  •  抹茶落季
    2020-12-15 04:40

    I tend to have either a config setting or use a directive for debug builds:

     #if DEBUG
        Debugger.Break();
     #endif
    

    or

    if(Settings.DebugBreak)
                Debugger.Break();
    

    I put that in the OnStart method of the service component. Then you are prompted automatically and attached to the process.

提交回复
热议问题