服务停止超时设置 [英] Service Stop timeout setting

查看:106
本文介绍了服务停止超时设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我的基于c#的Windows服务需要一段时间才能处理。我必须在整个地方发布

一堆资源,不幸的是,在我可以干净地离开之前,它可以花20到40秒。


偶尔,当我从服务小程序停止服务时,它会超时并显示一条错误消息,说该服务不是
响应。


我的问题:


1.停止服务的超时值是多少。它几乎是
似乎变量和随机,但也许这是我的想象。

2.有没有办法从服务内部更改超时(根据需要) ?

3.有没有办法与服务小程序通信并告诉它

取消停止请求?

4.有没有与服务小程序进行通信的方式并告诉它

服务现在处于中间状态并且无法停止

(用户友好的消息)。 />

谢谢。

Hello,

My c# based windows service takes a while to dispose. I have to release
bunch of resources all over the place and unfortunately it can take
20-40 seconds before I can cleanly exit.

Every now and then, when I stop the service from the Services applet, it
will timeout and bring up an error message saying that the service isn''t
responding.

My questions:

1. What is the timeout value for stopping the service. It almost
seems variable and random, but maybe it''s my imagination.
2. Is there a way to change the timeout from inside the service (as needed)?
3. Is there a way to communicate with the services applet and tell it
cancel the stop request?
4. Is there a way to communicate with the services applet and tell it
that the service is in the middle of something now and cannot be stopped
(a user-friendly message).

Thanks.

推荐答案

弗兰克,


您可以申报要通过

P / Invoke调用的SetServiceStatus方法。在处理对象时,您应该调用

SetServiceStatus,为传递给

dwCurrentState字段传递值SERVICE_STOP_PENDING >
函数。


ServiceHandle属性将返回你需要传递的句柄

作为该函数的第一个参数。 />

希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com

Frank Rizzo ; <无** @ none.com>在消息中写道

news:OU ************* @ TK2MSFTNGP15.phx.gbl ...
Frank,

You can declare the SetServiceStatus method to be called through
P/Invoke. While disposing your objects, you should make a call to
SetServiceStatus, passing a value of SERVICE_STOP_PENDING for the
dwCurrentState field of the SERVICE_STATUS structure that is passed to to
the function.

The ServiceHandle property will return the handle that you need to pass
as the first parameter to that function.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Rizzo" <no**@none.com> wrote in message
news:OU*************@TK2MSFTNGP15.phx.gbl...
你好,

基于我的c#的Windows服务需要一段时间来处理。我必须在整个地方释放大量的资源,不幸的是,在我可以干净地退出之前可能需要20-40秒。

我不时地停下来来自服务小程序的服务,它会超时并显示一条错误消息,说该服务没有响应。

我的问题:

1.停止服务的超时值是多少。它几乎似乎是变量和随机的,但也许这是我的想象。
2.有没有办法改变服务内部的超时(如需要的话)?
3.有没有办法与服务小程序通信并告诉它
取消停止请求?
4.有没有办法与服务小程序通信并告诉它
服务现在处于中间状态,无法停止(用户友好的消息)。

谢谢。
Hello,

My c# based windows service takes a while to dispose. I have to release
bunch of resources all over the place and unfortunately it can take 20-40
seconds before I can cleanly exit.

Every now and then, when I stop the service from the Services applet, it
will timeout and bring up an error message saying that the service isn''t
responding.

My questions:

1. What is the timeout value for stopping the service. It almost seems
variable and random, but maybe it''s my imagination.
2. Is there a way to change the timeout from inside the service (as
needed)?
3. Is there a way to communicate with the services applet and tell it
cancel the stop request?
4. Is there a way to communicate with the services applet and tell it that
the service is in the middle of something now and cannot be stopped (a
user-friendly message).

Thanks.



我担心我对你的#3没有明确的答案,但是对于1,2和4我有一些




1 。服务启动时Windows的超时时间为30秒,或者关闭
,所以如果在该窗口中没有完成所需的操作,那么

会导致进程终止。 />

2. AFAIK没有办法动态更改你可以指定为REG_DWORD(以毫秒为单位)命名为Ser的超时时间vicesPipeTimeout
HKEY_LOCAL_MACHINE \ System \ CurrentControlSet \Contro l里面的
这个值

在windows启动时指定将是什么直到

更改并重新启动。


4.如果您的服务控制应用程序和您的服务是.NET应用程序,

查看CanStop属性ServiceBase和ServiceController

类(或两者的衍生物)。正如您可能从名称中猜到的那样,您可以使用它来获取并设置服务在其启动后停止的能力




Brendan

Frank Rizzo写道:
I fear that I do not have definite answers for your #3, however I do have
some for 1, 2 and 4.

1. Windows has a timeout of 30 seconds for services when they startup or
shutdown so if the desired operation has not completed in that window, it
kills the process.

2. AFAIK there is no way to dynamically change the timeout time which you
can specify as a REG_DWORD (in milliseconds) named ServicesPipeTimeout
inside of HKEY_LOCAL_MACHINE\System\CurrentControlSet\Contro l as this value
specirfied at the time of windows starting up will be what is used until
changed and rebooted.

4. If your service controlling app and your service are .NET applications,
look into the CanStop property of the ServiceBase and ServiceController
classes (or your derivatives of both). As you might guess from the name, you
can use it to get and set the ability of the service to be stopped after it
is started.

Brendan
"Frank Rizzo" wrote:
你好,

基于我的c#的Windows服务需要一段时间来处理。我必须在整个地方释放大量的资源,不幸的是它可能需要20-40秒才能完全退出。

我时不时地停下来来自服务小程序的服务,它会超时并显示一条错误消息,说该服务没有响应。

我的问题:

1.停止服务的超时值是多少。它几乎似乎是变量和随机的,但也许这是我的想象。
2.有没有办法从服务内部(根据需要)更改超时?
3.是有没有办法与服务小程序进行通信并告诉它
取消停止请求?
4.有没有办法与服务小程序通信并告诉它
服务是在中间的东西现在,不能停止
(一个用户友好的消息)。

谢谢。
Hello,

My c# based windows service takes a while to dispose. I have to release
bunch of resources all over the place and unfortunately it can take
20-40 seconds before I can cleanly exit.

Every now and then, when I stop the service from the Services applet, it
will timeout and bring up an error message saying that the service isn''t
responding.

My questions:

1. What is the timeout value for stopping the service. It almost
seems variable and random, but maybe it''s my imagination.
2. Is there a way to change the timeout from inside the service (as needed)?
3. Is there a way to communicate with the services applet and tell it
cancel the stop request?
4. Is there a way to communicate with the services applet and tell it
that the service is in the middle of something now and cannot be stopped
(a user-friendly message).

Thanks.



我因为我已经在所有版本中编写了许多服务,因此我可以帮助解决这个问题

的NT自3.0以来 - 但我没有必要在一段时间内做服务所以我的具体细节

有褪色...


此外,与.NET服务包装器一样方便,它们不会公开WIN32 API实现的所有功能。为了做一些你想要做的更高级的事情,你必须通过

thes服务API做一些PInvoke:

http ://msdn.microsoft.com/library/de..._functions.asp
I can help with generalities as I have written many services in all versions
of NT since 3.0 - but I haven''t had to do services in awhile so my specifics
have faded...

Also, as convenient as the .NET service wrappers are they do not expose all
of the functionality that the WIN32 API implements. In order to do some of
the more advanced things you want to do you will have to do some PInvoke via
thes service APIs:

http://msdn.microsoft.com/library/de..._functions.asp
1.停止服务的超时值是多少。它几乎似乎是变量和随机的,但也许这是我的想象力。


我相信它在注册表中,您可以更改它。但是,它是一台机器宽的设置,所以你需要管理员权限来改变它。另外,如果你缩短它,你可以很容易地导致其他人的服务在退出时崩溃...

{也称不改变默认值}

2.有没有办法从服务内部更改超时(根据需要)?


如果停止请求已经到达,你必须在系统配置的任何

超时窗口中关闭,和以前一样,你可能不要
想要搞乱超时设置......

但是你可以在转换过程中对SetStatus()进行未经请求的调用

从跑步到停止。每次通过

SetStatus(Stop Pending)通知SCM时,超时计数器都会重置:)。更多信息在

文档中为SetStatus()...

3.有没有办法与服务小程序进行通信并告诉它
取消停止请求?


另请参阅HandlerEx() - 您的服务中可以有一个回调例程

响应自定义服务命令。你也可以{和我经常}在我的服务中有一个

专用线程,它使用远程处理或套接字等来支持
与外界沟通。

4.有没有办法与服务小程序进行通信,并告诉它
服务现在处于中间状态并且无法停止
(用户友好的消息)。
1. What is the timeout value for stopping the service. It almost
seems variable and random, but maybe it''s my imagination.
I believe it is in the registry and you can change it. However it is a
machine wide setting so you need admin powers to alter it. Also, if you
shorten it you can easily cause somebody else''s service to crash on exit...
{aka changing the default is not recommended}
2. Is there a way to change the timeout from inside the service (as needed)?
If the stop request has arrived already you''ve got to shut down in whatever
timeout window the system is configured for and as before, you probably don''t
want to mess with the timeout setting...

HOWEVER you can make ''unsolicited'' calls to SetStatus() while transitting
from running to stopped. Each time that you notify the SCM via
SetStatus("Stop Pending") the timeout counter is reset :). More info in the
docs for SetStatus()...
3. Is there a way to communicate with the services applet and tell it
cancel the stop request?
See also HandlerEx() - you can have a callback routine in your service that
responds to a custom service commands. Also you can {and I often do} have a
dedicated thread in my service that uses remoting or sockets, etc. to
communicate with the outside world.
4. Is there a way to communicate with the services applet and tell it
that the service is in the middle of something now and cannot be stopped
(a user-friendly message).




请参阅.NET ServiceController类。您可以设置CanStop = false;物业

和服务禁用停止命令...


此外,这不是一个好主意但可能,你可以附加到任何/所有用户的

桌面和显示消息框等。除了是一个令人愤怒的

编程家务{trust me}这会遇到类似的问题 - 到哪个桌面
如果机器上有多个桌面打开,我会附上
,这对我来说是安全的,可以在目标上抛出一个可能是模态的对话框桌面?? -

Yukk !!!


- 理查德



See .NET ServiceController class. You can set "CanStop = false" property
and the stop command is disabled for the service...

Also, not such a great idea but possible, you can attach to any/all user''s
desktop''s and display message boxes etc. Aside from being an infuriating
programming chore {trust me} this gets into issues like - to which desktop
shall I attach if there are multiple desktop''s open on the machine, and is it
safe for me to throw up a, probably modal, dialog on a targeted desktop?? -
Yukk!!!

--Richard


这篇关于服务停止超时设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆