I have .NET service and I need to debug it.
I want it to stop when it reaches some place in code and start the debugger. Can anyone provide some code sample?
UPDATE
Simply adding
Debugger.Launch();
does not开发者_Go百科 work for Windows service.
Try using Debugger.Break()
, as per this answer.
Add a Debugger.Launch();
to the place in your code where you want to start debugging.
- Add the following code to the place where you want to stop service.
- Run Service.
- Attach debugger
- Add f to watch, change it value to false
Continue debugging
bool f=true; while(f) {//<- Add breakpoint here
}
Here are the steps for that:
1) Stop & uninstall the running service 2) Rename or remove the release version of the service 2) Create a Debug build of the service 3) Install this debug build of service 4) Start the service 5) Open the service solution from Visual studio 6) Select Tools->Attach process 7) In the process list you will see the running service, Attach it 8) Set breakpoints wherever required
精彩评论