首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
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

Stack Overflow用户

回答已采纳

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

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

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

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

票数 4
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5356360

复制
相关文章

相似问题

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