I\'ve got a windows service written in C#. I\'ve read all the google threads on how to debug it, but I still can\'t get it to work. I\'ve run \"PathTo.Net
Assumptions:
1) You have the source code available in a Solution in the VS2008 IDE
How I Debug C# Services:
InstallUtil. (You seem like you've already done that)bin folderPut something like the following at the beginning of your Service's OnStart() method:
while(true)
{
System.Threading.Thread.Sleep(500);
}
Put a breakpoint on System.Threading.Thread.Sleep(500)
Build the Solution
Start your Service using the Windows Service Utility
While your Service is starting, in VS2008 goto Debug -> Attach To Processes...
Make sure Show Processes From All Users and Show Processes In All Sessions are checked
Find your MyService.exe in the list, and click Attach
You should now be at the breakpoint you inserted in the infinite loop
Drag the Control (Yellow Arrow) just outside the infinite loop
Debug away!
Disclaimer:
Remember to remove the infinite loop when you want to release a build, or when you simply want to run the service normally.