Windows 服务错误 1053 [英] Windows Service Error 1053
问题描述
我目前正在编写一个 Windows 服务,它连接到一个 crm 系统来拉下一个计划,然后运行各种数据馈送等.除了当我安装所有东西并尝试运行启动服务时我得到了以下错误:
I'm currently writing a windows service which connects to a crm system to pull down a schedule which then runs various datafeeds etc. I've got everything working except when I install everything and try to run start the service I get the following error :
错误 1053:服务没有响应启动或控制请求及时时尚"
"Error 1053: The service did not respond to the start or control request in a timely fashion"
这是我在 Service1.cs 中使用的代码;
Here's the code I'm using in my Service1.cs;
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中如下
Then the following in the Service1.Designer.cs
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 中的以下内容
And lastly the following in ProjectInstaller.cs
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);
}
}
}
推荐答案
经过大量调查和修复一堆问题",结果证明与问题无关,我发现我需要以下内容在服务的 Main() 方法中;
After a lot of investigation and fixing a whole bunch of "problems" which turned out to be nothing to do with the issue, I discovered that I needed the following in the Main() method of the service;
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
由于添加了这个,现在一切似乎都运行良好,服务按预期启动.
As a result of adding this everything seems to work perfectly now, the service starts as expected.
这篇关于Windows 服务错误 1053的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!