Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

.net - How to debug a windows service using breakpoints?

I have a windows service with a timer. Its very hard to debug it. Because I start the service and put break points in different parts of the code. When I attach the process, I expect the service to start from the very beginning instead of some randome place in the middle code where I have break points. Its hard to debug like a normal application where you know the starting point. It appears that there are processes in the back ground that have not completed yet. So every single time, I start to debug, instead of starting from the very first break point, it starts from some random break point in the middle of application.

I want to know how windows service works in terms of processes, threads etc... and how can I start debugging from the beginning?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I assume you're talking about .Net of course. I've always used the following code to debug my services. I place it where I want to the debugger to launch. Start the service and it automatically launches Visual Studio. Works well for me.

System.Diagnostics.Debugger.Launch();

System.Diagnostics.Debugger.Debug();


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...