停止Windows服务。 [英] stopping windows service.

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

问题描述

大家好,


我有一个更新到数据库的Windows服务。


On''Onstop我想等直到当前更新完成。我将如何执行此操作?


因为如果我在onstop上写了一些冗长的代码,它就无法停止并且

状态仍然存在''停止''后来我无法对该服务做任何事情

即使我也无法卸载该服务。


请告诉我解决方案为此。


请尽快帮助我。


提前感谢。

Hi all,

I am having one windows service which is updating to database.

On ''Onstop i want to wait till current updation complete. How will i
do this?

Because if i write some lengthy code on onstop it fails to stop and
status remain ''stopping'' Later i can''t do anything on that service
even i can''t uninstall that service.

Please tell me solution for this.

Please help me asap.

thanks in advance.

推荐答案

我相信,一旦你进入OnStop,你已经调用了服务控制

经理,如果她不能在分配的时间内停止服务她会打击




如果不是,你可以检查操作是否完成并挽救。其他

人们做这样的事情:


private void InvokeOnStop()

{

ServiceController sc = new ServiceController(this.ServiceName);


sc.Stop();

sc.Dispose();

}


- 虽然目前的智慧表明这不是一个好主意。


彼得

- -

递归:见递归

网站: http ://www.eggheadcafe.com

unBlog: http: //petesbloggerama.blogspot.com

bogMetaFinder: http:/ /www.blogmetafinder.com


" archana"写道:
I believe that once you are in OnStop you''ve invoked the Service Control
Manager and if she can''t stop your service in the alloted time, she will blow
up.

You could check if the operation is complete and bail out if it isn''t. Other
folks do stuff like this:

private void InvokeOnStop()
{
ServiceController sc = new ServiceController(this.ServiceName);

sc.Stop();
sc.Dispose();
}

-- Although current wisdom indicates that it isn''t a good idea.

Peter
--
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com

"archana" wrote:

大家好,


我有一个更新到数据库的Windows服务。


On''Onstop我想等到当前的更新完成。我将如何执行此操作?


因为如果我在onstop上写了一些冗长的代码,它就无法停止并且

状态仍然存在''停止''后来我无法对该服务做任何事情

即使我也无法卸载该服务。


请告诉我解决方案为此。


请尽快帮助我。


提前感谢。

Hi all,

I am having one windows service which is updating to database.

On ''Onstop i want to wait till current updation complete. How will i
do this?

Because if i write some lengthy code on onstop it fails to stop and
status remain ''stopping'' Later i can''t do anything on that service
even i can''t uninstall that service.

Please tell me solution for this.

Please help me asap.

thanks in advance.





感谢您的回复。


但我将如何等待某些操作完成''onstop event''。

在windows服务中看到我可以通过使用waitall来促使用户等待一些

操作完成。这不会导致任何问题。就像我在windows服务中需要做的那样等待

当前操作完成。


如果你可以对它有所了解那么它将是对我很有帮助,


谢谢。

Hi,

thanks for your reply.

But how will i wait for some operation to complete on ''onstop event''.
See like in windows service i can forece user to wait for some
operation to complete by using waitall. That won''t cause any
problem. Like that what i need to do in windows service to wait for
current operation to complete.

if u can shed some light on it then it will be really helpful for me,

thanks.


" archana" < tr ************** @ yahoo.com写信息

新闻:11 **************** *****@d55g2000hsg.googlegro ups.com ...
"archana" <tr**************@yahoo.comwrote in message
news:11*********************@d55g2000hsg.googlegro ups.com...

但我将如何等待某些操作完成''onstop event''。

在Windows服务中看到我可以通过使用waitall来促使用户等待一些

操作完成。这不会导致任何问题。就像我在windows服务中需要做的那样等待

当前操作完成。


如果你可以对它有所了解那么它将是对我很有帮助,
But how will i wait for some operation to complete on ''onstop event''.
See like in windows service i can forece user to wait for some
operation to complete by using waitall. That won''t cause any
problem. Like that what i need to do in windows service to wait for
current operation to complete.

if u can shed some light on it then it will be really helpful for me,



我通常在进程启动时设置一个布尔标志为true,然后在进程结束时将其设置为

false。


在OnStop事件中,我检查标志的值并等到它是

false之后关闭服务。

-

Mark Rae

ASP.NET MVP
http://www.markrae.net

I usually set a boolean flag true when a process starts and then set it
false when the process ends.

In the OnStop event, I check the value of the flag and wait until it is
false before shutting down the service.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


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

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