什么是超时启动Windows服务?Windows

2023-09-03 05:11:42 作者:饮尽盏中余温

我已经部署了我的窗口服务(使用独立安装程序类和SC.EXE),但我得到一个错误,当我尝试启动:

I have deployed my windows service (using independently installer class and SC.EXE), but I get an error when I try to start it:

---------------------------
Services
---------------------------
Could not start the MyName service on Local Computer.



Error 1053: The service did not respond to the start or control request in a timely fashion.

什么是超时?这感觉就像约3秒。我需要什么,如果我的服务需要更长的时间呢?

What is the timeout? It felt like around 3 secs. What do I need to do if my service takes longer?

推荐答案

在服务类中,使用 ServiceBase.RequestAdditionalTime()在你的OnStart /的onStop方法:

In your service class, use ServiceBase.RequestAdditionalTime() in your OnStart/OnStop method:

// request an additional 4 seconds to complete the operation
RequestAdditionalTime(4000);