Before a Windows Service can run, it has to be "installed" first using installutil. EG:
C:installutil -i c:pathoprojectdebugservice.exe
Then you can open up the list of Services to start it. EG:
- Right click 'My Computer'
- Click on 'Manage'
- Open up 'Services and Applications'
- Click on 'Services'
- Find your service in the list and right-click on it
- Click on 'Start'
Once it has started, you can go into Visual Studio, click on 'Debug', then click on 'Attach to Process'.
Another technique is to add this line to your OnStart() method in the service:
System.Diagnostics.Debugger.Launch();
When you do that, it'll prompt you to pick an instance of Visual Studio to debug the service in.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…