Search code examples
.net-coreserviceregedit

.NET Core Error 1053 the service did not respond to the start or control request in a timely fashion


I created a Windows Service starting from my .NET Core project following this

After this, I installed correctly it on my working machine and started it.

This is my service class:

using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading.Tasks;

namespace xxx
{
    public class WindowsService
    {
        static void Main(string[] args)
        {
            System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

            using (var service = new Service())
            {
                ServiceBase.Run(service);
            }
        }
    }

    internal class Service : ServiceBase
    {
        public Service()
        {
            ServiceName = "...";
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                base.OnStart(args);
                Task.Run(() => xxxx);
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("Application", ex.ToString(), EventLogEntryType.Error);
            }
        }

        protected override void OnStop()
        {
            base.OnStop();
        }

        protected override void OnPause()
        {
            base.OnPause();
        }
    }
}

So, I copied the file and installed it also on a server. Here, when I try to start it, I get:

Error showed starting the service

After this, I start a lot of googling... for example, I tried the following steps :

Go to Start > Run > and type regedit

Navigate to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control

With the control folder selected, right click in the pane on the right and - select new DWORD Value

Name the new DWORD: ServicesPipeTimeout

Right-click ServicesPipeTimeout, and then click Modify

Click Decimal, type '180000', and then click OK

Restart the computer

The weird point here is that the voice ServicesPipeTimeout didn't exist and I created it. Comparing the server with my working machine, there are also other value not present in the server. They are:

  • ServicesPipeTimeout
  • OsBootstatPath

Here the screenshot of regedit from the server:

enter image description here

Are these relevant?

I also tried to reinstall the service, recompile my files... how can I fix this problem? The error appears immediatly, it doesn't wait any timeout!


Solution

  • I had this problem when I switched my project to another location.

    When I moved the project, I had copied the files in bin/debug folder too. The issue was resolved after I cleared the debug folder and created a new build.

    See if this works!