How do I debug Windows services in Visual Studio?

后端 未结 17 710
梦毁少年i
梦毁少年i 2020-11-28 03:56

Is it possible to debug the Windows services in Visual Studio?

I used code like

System.Diagnostics.Debugger.Break();

but it is givi

17条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 04:10

    You can also try this.

    1. Create your Windows service and install and start…. That is, Windows services must be running in your system.
    2. While your service is running, go to the Debug menu, click on Attach Process (or process in old Visual Studio)
    3. Find your running service, and then make sure the Show process from all users and Show processes in all sessions is selected, if not then select it.

    enter image description here

    1. Click the Attach button
    2. Click OK
    3. Click Close
    4. Set a break point to your desirable location and wait for execute. It will debug automatic whenever your code reaches to that point.
    5. Remember, put your breakpoint at reachable place, if it is onStart(), then stop and start the service again

    (After a lot of googling, I found this in "How to debug the Windows Services in Visual Studio".)

提交回复
热议问题