首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Windows服务错误1053

Windows服务错误1053
EN

Stack Overflow用户
提问于 2011-03-19 02:35:25
回答 3查看 7.8K关注 0票数 2

我目前正在编写一个windows服务,它连接到一个crm系统,以拉下一个时间表,然后运行各种datafeeds等。我已经让一切正常工作,除了当我安装所有东西并尝试运行启动服务时,我得到了以下错误:

“错误1053:服务未及时响应启动或控制请求”

下面是我在Service1.cs中使用的代码;

代码语言:javascript
复制
namespace FeedManagementService
{
  public partial class Service1 : ServiceBase
  {
    private System.Timers.Timer timer;

public Service1()
{
  InitializeComponent();
}

protected override void OnStart(string[] args)
{
  // Instantiate the timer
  Thread t = new Thread(new ThreadStart(this.InitTimer));
  t.IsBackground = true;
  t.Start();
} // OnStart

protected override void OnStop()
{
  timer.Enabled = false;
} // OnStop

private void InitTimer()
{
  timer = new System.Timers.Timer();

  // Add the timer event
  timer.Elapsed += new ElapsedEventHandler(timerTick);

  // Set the interval
  double timeInSeconds = 6.0;
  timer.Interval = (timeInSeconds * 1000);
  timer.Enabled = true;
} // InitTimer()

private void timerTick(object sender, EventArgs e)
{
  // CRM connection stuffhere
} // timerTick
  }
}

然后是Service1.Designer.cs中的以下内容

代码语言:javascript
复制
namespace FeedManagementService
{
  partial class Service1
  {
    /// <summary> 
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
      if (disposing && (components != null))
      {
        components.Dispose();
      }
      base.Dispose(disposing);
    }

    #region Component Designer generated code

    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.components = new System.ComponentModel.Container();
      this.ServiceName = "Feed Management Service";
      this.CanPauseAndContinue = true;
    } // InitializeComponent()

    #endregion
  }
}

最后,下面是ProjectInstaller.cs中的

代码语言:javascript
复制
namespace FeedManagementService
{
  [RunInstaller(true)]
  public partial class ProjectInstaller : System.Configuration.Install.Installer
  {
    public ProjectInstaller()
    {
      ServiceProcessInstaller process = new ServiceProcessInstaller();

      process.Account = ServiceAccount.LocalSystem;

      ServiceInstaller serviceAdmin = new ServiceInstaller();

      serviceAdmin.StartType = ServiceStartMode.Manual;
      serviceAdmin.ServiceName = "Service1";
      serviceAdmin.DisplayName = "Feed Management Service";
      Installers.Add(process);
      Installers.Add(serviceAdmin);
    }
  }
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-04-09 00:45:19

经过大量的调查和修复一大堆与问题无关的“问题”后,我发现我需要在服务的Main()方法中使用以下代码;

代码语言:javascript
复制
ServiceBase[] ServicesToRun;
  ServicesToRun = new ServiceBase[] 
        { 
            new Service1() 
        };
  ServiceBase.Run(ServicesToRun);

由于添加了这一点,现在一切似乎都很完美,服务按预期启动。

票数 4
EN

Stack Overflow用户

发布于 2011-03-19 03:48:43

您的OnStart()方法似乎未在允许的超时时间内返回。消息是立即显示,还是需要大约30秒才能显示?您的CRM Connection Stuff(tm)是否需要一些时间才能运行?

答:你的应用中有没有使用Windows.Forms的东西?这些不应该在服务上使用,并且可以以奇怪和神秘的方式进行交互。

票数 1
EN

Stack Overflow用户

发布于 2015-07-29 21:05:27

我遇到了同样的问题,完全不确定如何解决它。是的,发生这种情况是因为服务抛出了一个异常,但您可以遵循一些通用的指导原则来纠正此问题:

  • 检查您是否编写了正确的代码来启动服务:

新的文本;WinsowsServiceToRun

  • Finally,= ServiceBase[] ServicesToRun { ServiceBase[] () };ServiceBase.Run(ServicesToRun);

  • You需要确保类中运行着某种类型的无限循环WinsowsServiceToRun

  • Finally,可能有一些代码没有记录任何内容并突然关闭程序(我的情况就是这样),在这种情况下,你将不得不遵循旧的调试方法,需要编写一行代码到源文件(ServiceBase[]/db/ServiceBase.Run(ServicesToRun);

  • You)。我所面临的是,由于运行该服务的帐户不是"Admin",代码就会丢失,并且不会记录任何异常,以防它试图写入"Windows事件日志“,即使代码是用来记录异常的。管理员权限实际上不是登录到Even Log所必需的,但它是定义来源所必需的。如果系统中尚未定义事件源,并且该服务在没有管理员权限的情况下首次尝试记录该事件,则会失败。要解决此问题,请执行以下步骤:

使用管理员事件打开命令提示符privilege

  • Paste命令:
  1. 1 /L应用程序信息/SO <> /D“<>”
  2. 按enter
  3. Now启动服务
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5356360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档