gpt4 book ai didi

c# - 需要增加窗口服务超时

转载 作者:太空狗 更新时间:2023-10-29 20:56:40 27 4
gpt4 key购买 nike

我在启动窗口服务时遇到问题...由于我的服务的 OnStart() 事件负载很大,它会废弃数据,将其保存到数据库并发送电子邮件。所以我的服务需要增加开始时间,因为默认超时是 30 秒...我已经发布,当我遇到以下异常时,我的服务将需要额外的时间来启动。

"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."

请帮帮我...提前致谢

最佳答案

i have realised that my service will need additional time to start when i face the following exception

在构造函数/启动时执行长时间运行的任务并不好。你应该在一个单独的线程上开始你的长期运行任务。

服务启动应该是即时的,不应该挂掉。

如果你还想,你可以这样做

ServiceBase.RequestAdditionalTime(4000); // add 4 seconds

来自 MSDN

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.

关于c# - 需要增加窗口服务超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18380060/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com