Error 1053 the service did not respond to the star

2020-05-18 04:27发布

I have created and installed a service a couple of times. Initially it was working fine, but after some changes in the service Code it start giving the error when I restart the service in Services.msc :

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

Code:

public partial class AutoSMS : ServiceBase
{
    public AutoSMS()
    {
        InitializeComponent();
        eventLog1.Clear();

        if (!System.Diagnostics.EventLog.SourceExists("MySource"))
        {
            System.Diagnostics.EventLog.CreateEventSource(
                "MySource", "MyNewLog");
        }
        eventLog1.Source = "MySource";
        eventLog1.Log = "MyNewLog";

        Timer checkForTime = new Timer(5000);
        checkForTime.Elapsed += new ElapsedEventHandler(checkForTime_Elapsed);
        checkForTime.Enabled = true;

    }

    protected override void OnStart(string[] args)
    {
        eventLog1.WriteEntry("In OnStart");
    }

    protected override void OnStop()
    {
        eventLog1.WriteEntry("In onStop.");
    }


    void checkForTime_Elapsed(object sender, ElapsedEventArgs e)
    {
        string Time = "15:05:00";
        DateTime dateTime = DateTime.ParseExact(Time, "HH:mm:ss",
                                        CultureInfo.InvariantCulture);

        if (DateTime.Now == dateTime) ;
            eventLog1.WriteEntry(Time);
    }
}

Here is my main method code

static void Main()
{
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[] 
    { 
        new AutoSMS() 
    };
    ServiceBase.Run(ServicesToRun);
}

I also 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

I used to install and uninstall it with following command :

installutil AutoSMS.exe

installutil /u AutoSMS.exe

标签: c# .net timer
30条回答
啃猪蹄的小仙女
2楼-- · 2020-05-18 05:05

My issue was the one with appsettings.json not copying to release build folder during build and simple putting it into the ...\bin\Release folder and copying launchSettings.json content to appsettings.json solved the problem for me.

查看更多
smile是对你的礼貌
3楼-- · 2020-05-18 05:06

I have installed .Net 4.6 on my WindowsServer computer and the error was fixed.

Your control should be this way:

  1. Check the .net version of your WindowsService
  2. Then check the .net version of your computer
  3. Match that version, since it's probably not matched
查看更多
叼着烟拽天下
4楼-- · 2020-05-18 05:06

one possible reason is:

mismatch of windows service .net version & your system .net version.

查看更多
再贱就再见
5楼-- · 2020-05-18 05:07

In my case I apparently had some extra symbols in my App.config file that I did not notice when building my solution. So I recomend to check the configuration file for errors first before taking steps with changing registry keys, switching configuration modes, etc.

查看更多
家丑人穷心不美
6楼-- · 2020-05-18 05:07

I had two services running who were accidentally coupled to the same EventSource eventLog.Source = "MySource"; After uninstalling both services, and reinstalling the one that suffered from error 1053, my service started up normally.

查看更多
我只想做你的唯一
7楼-- · 2020-05-18 05:09

I had the same issue. Seems like when starting the service the main thread shouldnt be the main worker thread. By simply creating a new thread and handing the main work to that thread solved my issue.

查看更多
登录 后发表回答