【问题标题】:Error 1053 the service did not respond to the start or control request in a timely fashion错误 1053 服务没有及时响应启动或控制请求
【发布时间】:2014-08-05 08:52:54
【问题描述】:

我已经创建并安装了几次服务。最初它工作正常,但是在服务代码中进行了一些更改后,当我在 Services.msc 中重新启动服务时它开始给出错误:

错误 1053:服务没有及时响应启动或控制请求

代码:

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);
    }
}

这是我的主要方法代码

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

我也尝试了以下步骤:

  • 转到开始 > 运行 > 并键入 regedit
  • 导航到:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
  • 选中控制文件夹后,右键单击右侧窗格并 - 选择新的 DWORD 值
  • 将新的 DWORD 命名为:ServicesPipeTimeout
  • 右键单击 ServicesPipeTimeout,然后单击修改
  • 点击十进制,输入“180000”,然后点击确定
  • 重启电脑

我曾经使用以下命令安装和卸载它:

installutil AutoSMS.exe

installutil /u AutoSMS.exe

【问题讨论】:

  • Windows 事件日志说明了什么?还是说Error 1053?这可能是一个权利问题。尝试以Local System 用户身份运行服务。
  • 将来在 Main() 方法中使用 System.Diagnotstics.Debugger.Launch() 可能会很有用,这样您就可以使用调试器了。

标签: c# .net timer windows-services


【解决方案1】:

安装 .net 框架 4.5!它对我有用。

https://www.microsoft.com/en-us/download/details.aspx?id=57768

【讨论】:

    猜你喜欢
    • 2011-03-28
    • 2011-01-05
    • 2011-12-29
    • 2015-12-28
    • 2023-03-23
    • 1970-01-01
    • 2016-03-22
    • 2013-12-20
    相关资源
    最近更新 更多