Cool Code For Testing Windows Services
Windows Services are great. They allow you to write code that will run even when a user is not logged in. They can perform functions in the background, and they’re very useful.
Writing them, however, is a little more interesting.
If you were to simply open Visual Studio and create a new Windows Services project and start coding, you wouldn’t be able to tell if the code was doing what you wanted without installing it as a service.
And even then, you won’t be able to see what happened (was it successful?!) until you go to an event log– if there were any events generated.
That’s when I stumbled upon this neat project over at CodeProject that allows you to Debug a Windows Service without deploying it. Basically, all you have to do is include a ServiceRunner project in your solution, hook it up into your project, and change your Main function in your Program.cs.
It provides you with a Windows Forms application that looks like this:
And you can start your service just like the system will–and set breakpoints for debugging.
So, if you’re into creating Windows Services, head on over and check out this handy chunk of code!