windows service startup timeout

前端 未结 4 736
粉色の甜心
粉色の甜心 2020-11-29 21:42

Is there a way to set a different value for service startup timeout per service? I can change it using the ServicesPipeTimeout registry key, but it\'s per machine (http://su

4条回答
  •  情歌与酒
    2020-11-29 22:12

    I also had to deal with a service which may takes a few seconds/minutes to have a good Start. When the service starts, it tries to connect to a SQL Server. However, when the whole server was restarted , my service was starting BEFORE SQL Server. (I know about the Service dependency but it dont apply to my situation for a particular reason....). I tried to do a loop trying 10 times to connect to SQL Server, but Windows was killing my service before the 2nd try, because of the Timeout.

    My solution : I added a Timer in the "onStart()" of my service. Then, the "onTick()" method of the service was trying 10 times to connect to the SQL Server (with a waiting of 30 in it). No more Timeout at startup.

    So basically,

    • My service starts in 5 seconds.
    • A timer is launched 10 seconds after the service is started.
    • The timer tries 10 times [waiting 30 seconds each time] to connect to the SQL Server.
    • If it succeed, the timer will disable itself, if not (after 10 try), I stop the service.

    Note the more elegant way to resolve the problem but maybe some part of my solution may help anybody in the same situation than me,

提交回复
热议问题