我目前正在编写一个windows服务,它连接到一个crm系统,以拉下一个时间表,然后运行各种datafeeds等。我已经让一切正常工作,除了当我安装所有东西并尝试运行启动服务时,我得到了以下错误:
“错误1053:服务未及时响应启动或控制请求”
下面是我在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中的以下内容
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中的
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);
}
}
}发布于 2011-04-09 00:45:19
经过大量的调查和修复一大堆与问题无关的“问题”后,我发现我需要在服务的Main()方法中使用以下代码;
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);由于添加了这一点,现在一切似乎都很完美,服务按预期启动。
发布于 2011-03-19 03:48:43
您的OnStart()方法似乎未在允许的超时时间内返回。消息是立即显示,还是需要大约30秒才能显示?您的CRM Connection Stuff(tm)是否需要一些时间才能运行?
答:你的应用中有没有使用Windows.Forms的东西?这些不应该在服务上使用,并且可以以奇怪和神秘的方式进行交互。
发布于 2015-07-29 21:05:27
我遇到了同样的问题,完全不确定如何解决它。是的,发生这种情况是因为服务抛出了一个异常,但您可以遵循一些通用的指导原则来纠正此问题:
新的文本;WinsowsServiceToRun
使用管理员事件打开命令提示符privilege
https://stackoverflow.com/questions/5356360
复制相似问题