2

I have written a windows service application which is installed on my PC. There is a problem with it, so I want to debug that service.

Can you tell me how to debug the windows services?

1
  • This question has been ask umpteen times. Please search before asking. Commented Jul 30, 2010 at 7:02

4 Answers 4

2

Please read: http://msdn.microsoft.com/en-us/library/7a50syb3(VS.80).aspx

Sign up to request clarification or add additional context in comments.

Comments

1

The easiest way to debug code that you've written as a service in .NET is to separate all the functional code from the service into a separate assembly and then create another project, as a console or WinForms application that uses the separate assembly to run the service code.

3 Comments

+1 I had to do this once, and i found this to be far more convenient, not to mention the side effect of code encapsulation that you get.
+Roberto - yeup, I've always considered it to be by far the better option than trying to debug a service process, especially given the side effect you gain =)
If you use the TopShelf library then you get this as a side effect for free. You can either run your console app as a console app or as a service.
0

If you have Visual Studio on same machine, use it to list the process and attach a debugger to it. You can also use remote debugging but it can be a pain to configure.

Comments

0

The easiest way is to add System.Diagnostics.Debugger.Launch() to the point you want to start debugging. Visual Studio will need to be running as Administrator. When the code is executed, a dialog will pop up asking which instance of Visual Studio you want to use to debug. If you've got Visual Studio already open with the relevant project loaded, choose that one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.