I have a .Net service that has begun to refuse to start - the system log shows that it "was successfully sent a start control" and then five seconds later the "service entered the stop state". I have the Main() function of my service class wrapped in a try/catch block -- but when this situation occurs, no errors appear in my events log from my service.
I would like to know what the problem is. If there is some exception that is not being caught - where would it be caught? Below is the code in which I run the service.
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
namespace MyServerService
{
static class service
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
try
{
#if DEBUG
System.Diagnostics.Debugger.Launch();
#endif
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new MyService()
};
ServiceBase.Run(ServicesToRun);
} catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("MyServerService", "Main() Error: " + ex.Message + ex.InnerException, System.Diagnostics.EventLogEntryType.Error);
}
}
}
}