Amit Patil
Amit Patil

Reputation: 1993

How to debug a Windows Service

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?

Upvotes: 2

Views: 273

Answers (4)

Jack Hughes
Jack Hughes

Reputation: 5654

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.

Upvotes: 0

seand
seand

Reputation: 5286

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.

Upvotes: 0

Rob
Rob

Reputation: 45761

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.

Upvotes: 1

Related Questions