Windows服务无法开始.停止并显示错误1053. [英] windows service not getting started. stops with error 1053.

查看:192
本文介绍了Windows服务无法开始.停止并显示错误1053.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我一直在努力寻找导致自定义Windows服务停止的原因.我已经使用"InstallUtil.exe"通过命令提示符部署了Windows服务"C".在启动我的服务时,它会引发以下错误:

I have been trying hard to find the reason that is causing my custom windows service stop. I have deployed my windows service 'C' through command prompt using 'InstallUtil.exe'. On starting my service, it throws this error:

由于Windows服务是Windows的特色,因此我检查了事件查看器-> Windows日志->应用程序:

Since windows service is a windows characteristic, I checked my event viewer->windows log->application:

根据论坛:

According to the forum: msdn forum, the registry setting is to be modified. But, is that really the most reliable option?! On changing registry, will other files get affected?Also, the event id that I received is 7009. According to the above link, the event id 7000 or 7011 is timeout error, which I didn't receive. How can I get through this?

感谢和问候,

Nidhin Nambiar

Nidhin Nambiar

推荐答案

如果您的服务启动速度不够快,则会发生此错误.对于那些从来没有写过服务的人来说,最常见的原因是他们认为他们应该在OnStart中进行工作.实际上,服务必须 是多线程的.服务的OnStart方法需要将其所有功能移至工作线程,在该工作线程中它将运行直到服务停止.调用OnStart的线程可以使用多少时间受到限制.如果超过该时间,则为 强行终止,您会遇到您提到的错误.

This error occurs if your service does not start fast enough. The most common cause I see for people having this issue when they have never written a service before is for them to assume that they should be doing their work in OnStart. In fact services must be multi-threaded. Your service's OnStart method needs to move all its functionality to a worker thread where it will run until the service is stopped. The thread that calls OnStart is limited in how much time it can use. If it exceeds that time then it is forcefully terminated and you get the error you mention.

OnStart唯一应做的工作是启动服务程序实际工作所在的工作线程所需的初始化代码.很少需要延长启动服务所需的时间.这几乎总是表明您 做错了事.这是OnStart应该使用的样板代码.

The only work that should be in OnStart is the necessary init code to start the worker thread where your service's real work will reside. It is rare that you should extend the time needed for your service to start. This is almost always an indication your doing something wrong. Here's the boilerplate code that OnStart should use.

void OnStart ( string[] args )
{
   //Verify arguments
   //Prep for starting worker
   _terminationEvent.Reset();

   //Start worker
   _worker = Thread.Start(DoWork);
}

void OnStop ()
{
   //Tell worker to terminate
   _terminationEvent.Set();

   //Wait for worker to terminate
   _worker.Join();
}

void DoWork ()
{
   while (!_terminationEvent.WaitOne(0))
   {
      //Keep doing your work
   };
}

private Thread _worker;
private ManualResetEvent _terminationEvent = new ManualResetEvent(false);

迈克尔·泰勒
http://www.michaeltaylorp3.net

Michael Taylor
http://www.michaeltaylorp3.net


这篇关于Windows服务无法开始.停止并显示错误1053.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆