How to debug a Windows Service
I have written a windows service application which is installe开发者_StackOverflow社区d 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?
Please read: http://msdn.microsoft.com/en-us/library/7a50syb3(VS.80).aspx
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.
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.
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.
精彩评论