Recently I had to develop my first Windows
Service in C#. I had already done Services in C++, and I was used to launch and
debug the Services thru Visual Studio (just by normally hitting F5). 

I was surprised to see that the normal C# Windows
Service code base does not allow this to be possible in a "out-of-the-box"
experience, and one had to do things like "Attach to Process", and/or put in
the source code "System.Diagnostics.Debugger.Launch();".

Not satisfied with these solutions, I searched
the web and I found this page that as a "perfect solution".

http://theimes.com/archive/2006/12/28/Debugging-Windows-Services-is-a-Pain.aspx

The author developed a Service Debugger Helper
class, that incorporates a GUI for allowing all the expected Start, Stop, etc,
interaction with the service. It is also possible to automatically start a
service by default, thus allowing the normal F5 experience.

Check out the author article and his source
code if you are interested in knowing how he made this. Also this other link
could be of interest to someone.

Run a Service without a debugger attached (.NET
Windows Service Runner)

http://theimes.com/archive/2007/08/22/net-windows-service-runner.aspx

PS: Regarding the usage of Timers in Windows
Services, be careful to use the ones in System.Timers.Timer, or else the timer may never (or
stop) be (being) fired.

LEAVE A REPLY

Please enter your comment!
Please enter your name here