How to debug Windows services in Visual Studio?

Yo can find this solution from http://stackoverflow.com/questions/4678819/how-to-debug-windows-services-in-visual-studio 
or
http://msdn.microsoft.com/en-us/library/7a50syb3(v=vs.110).aspx
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 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
If your debugger is not working due to any reason then you may add this line of code in your service.
Use following Code in Service OnStart Method:
System.Diagnostics.Debugger.Launch();
Choose Visual Studio option from Pop Up message 

Comments

Popular posts from this blog

Executing PowerShell scripts from C#

HOW TO Use the NumericUpDown Control

Exposing Agile Software Development Myths