Tuesday, September 30, 2014

The service on Local Computer started and then stopped

I was seeing the below error on a windows service that I had created.

---------------------------
Services
---------------------------
The xxx service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
---------------------------
OK  
---------------------------

The easiest way to debug this error was to launch the debugger from the service in the OnStart method like below:

protected override void OnStart(string[] args)
{
     System.Diagnostics.Debugger.Launch();
     // Rest of your code
}