需要增加窗口服务超时时间 [英] Need to increase window service timeout
问题描述
我在启动窗口服务时遇到问题...由于我的服务的 OnStart() 事件负载很大,它会废弃数据,将其保存到数据库并发送电子邮件.所以我的服务需要增加启动时间,因为默认超时是 30 秒...我已经发布,当我遇到以下异常时,我的服务需要额外的时间才能启动..
i am facing problem during starting my window service... as there is a big load on OnStart() event of my service, it scrap data, saved it to database and send email. So my service need to increase start time because the defualt timeout is 30second... i have released that my service will need additional time to start when i face the following exception..
无法在本地计算机上启动 MyName 服务.错误 1053:服务没有及时响应启动或控制请求时尚."
"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."
请帮帮我...提前谢谢
Plz help me... Thanx in advance
推荐答案
我意识到当我遇到以下异常时,我的服务需要额外的时间来启动
i have realised that my service will need additional time to start when i face the following exception
在构造函数/启动时执行长时间运行任务并不好.你应该在一个单独的线程上开始你的长时间运行的任务.
doing long runnings tasks on constructor/start isn't good. you should start your long running task on a sperate thread.
服务启动应该是即时的,不应该挂断.
Service startup should be instant and should not hang up.
但是如果你仍然想要,你可以这样做
However if you still want, you can do this
ServiceBase.RequestAdditionalTime(4000); // add 4 seconds
来自 MSDN
RequestAdditionalTime 方法旨在由覆盖 OnContinue、OnPause、OnStart 或 OnStop 方法来请求挂起操作的额外时间,以防止服务控制管理中心 (SCM) 将服务标记为未响应.如果挂起的操作不是继续、暂停、开始或停止,抛出 InvalidOperationException.
The RequestAdditionalTime method is intended to be called by the overridden OnContinue, OnPause, OnStart, or OnStop methods to request additional time for a pending operation, to prevent the Service Control Manager (SCM) from marking the service as not responding. If the pending operation is not a continue, pause, start, or stop, an InvalidOperationException is thrown.
这篇关于需要增加窗口服务超时时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!