Debugging Windows Services in C#

If you are trying to debug a windows service that you wrote in C# and find that when you go to attach to the process it is grayed out then you can solve the problem by inserting the following code into an appropriate place in your C# windows service code. This will bring up a dialog box and allow you to attach to your windows service.