This issue seems to be widely discussed, but I have problems with finding the solution in my particular case.
My service is set up to be running under Local System
account. On my first machine with Windows 7 SP1 (64-bit) installed, everything works as expected. But, just after I try to start the service on my second machine with Windows Server 2008 R2 SP1 (64-bit), not even a second passes, and I'm facing this annoying error:
Windows could not start the ProService service on Local Computer
Error 1053: The service did not respond to the start or control request in a timely fashion
The System Log
shows 2 entries:
The ProService service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion.
and:
A timeout was reached (30000 milliseconds) while waiting for the ProService service to connect.
The implementation looks following:
Program.cs:
static void Main()
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
ServiceBase.Run(new ServiceBase[] { new ProService() });
}
static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e != null && e.ExceptionObject != null)
{
Logger.Record(e.ExceptionObject);
}
}
ProService.cs:
public ProService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
RequestAdditionalTime(10000);
FireStarter.Instance.Execute();
}
catch (Exception e)
{
Logger.Record(e);
throw;
}
}
The OnStart
method is just starting a new thread, so it takes almost NO time load to execute. I used RequestAdditionalTime
statement just in case - to reject this matter as a source of my problem. In addition, as you can see, I'm handling all of the exceptions, but no exception is written to my custom service event log during the startup (btw: logging is working on the first win7 machine). How to investigate what's going on ?
I've figured out what was going on in a few steps:
OnStart
method from service.I've compared 2 configs - from service, and original from console application. As a result I've found some differences. Among others, there was such an entry - the source of the problem (after removal, everything works):
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
So basically I had out of date configuration file. Previously service was compiled under .NET 4.5, then I've changed the framework to 4.0 and deployed files to the server, but left the previous configuration file (I've changed the target framework because my development machine has .NET 4.5 while server does not). I wouldn't have thought the shown lines would hide all problems without any reasonable information, which could help to track the mess.