加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 17:38:07 所属栏目:百科 来源:网络整理
导读:我在启动窗口服务时遇到问题… 因为我的服务的OnStart()事件有很大的负担,它会废弃数据,将其保存到数据库并发送电子邮件.所以我的服务需要增加开始时间,因为defualt超时是30秒…… 我已经发布了当我遇到以下异常时我的服务需要额外的时间才能开始. “Could n
我在启动窗口服务时遇到问题…
因为我的服务的OnStart()事件有很大的负担,它会废弃数据,将其保存到数据库并发送电子邮件.所以我的服务需要增加开始时间,因为defualt超时是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.”

Plz帮帮我……
Thanx提前

解决方法

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

在构造函数/启动上执行长运行任务并不好.你应该在sperate线程上开始你的长期运行任务.

服务启动应该是即时的,不应该挂断.

但是,如果你仍然想要,你可以这样做

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读