Search code examples
c#visual-studiovisual-studio-2010windows-services

How do I debug Windows services in Visual Studio?


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

I used code like

System.Diagnostics.Debugger.Break();

but it is giving some code error like:

I got two event error: eventID 4096 VsJITDebugger and "The service did not respond to the start or control request in a timely fashion."


Solution

  • 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".)