Showing posts with label windows services. Show all posts
Showing posts with label windows services. Show all posts

Friday, June 12, 2009

Debugging Windows Services

Hey Guys!

This post is some info. about windows services. There are lot of blog posts/tutorials floating around in the web that deals with creation of windows services. But this post deals with the methods to debug a windows service. After you start your service you can attach it to a debugger, so that you can debug a windows service! Conventionally it wouldn't be possible to debug a windows service by pressing F5, as you would have known. This is because services are run from the context of a services control manager.

Now let me stop these stories and get directly in to reality!!

In a nutshell, these are the steps to be followed:

* Develop the service
* Start the service
- Start / Control Panel / Administrative Services / Computer Management
- Click on Services and Applications / Services
- Scroll to your service
- Start it (Right click - start)
* Open your project for this service in VS.Net
* Set breakpoints (Obviously you cannot debug the onStart method or the Main method!)
* Choose Debug -> Processes
* Choose the windows service in the list of "Available Processes"
* Click on "Attach"

There you go!! Hope this helps somebody!!!

Want a "professional" view of the same? Refer to,

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

Happy coding :)