Easier way to debug a Windows service

后端 未结 28 2043
春和景丽
春和景丽 2020-11-22 15:36

Is there an easier way to step through the code than to start the service through the Windows Service Control Manager and then attaching the debugger to the thread? It\'s ki

28条回答
  •  再見小時候
    2020-11-22 16:13

    For routine small-stuff programming I've done a very simple trick to easily debug my service:

    On start of the service, I check for a command line parameter "/debug". If the service is called with this parameter, I don't do the usual service startup, but instead start all the listeners and just display a messagebox "Debug in progress, press ok to end".

    So if my service is started the usual way, it will start as service, if it is started with the command line parameter /debug it will act like a normal program.

    In VS I'll just add /debug as debugging parameter and start the service program directly.

    This way I can easily debug for most small kind problems. Of course, some stuff still will need to be debugged as service, but for 99% this is good enough.

提交回复
热议问题