在服务启动时处理异常 [英] Handle exception on service startup
问题描述
OnStart()
方法中)。我假设只是在 OnStart()
中抛出一个错误,可以这样做,但我发现,而是开始,并向我发送一条消息,指出服务已经开始,但是没有活动,这是正确的吗? (释义)。如何处理错误,以致实际上无法启动服务?如果您正在运行.NET 2.0或更高版本,您可以使用 ServiceBase.Stop 停止服务从OnStart。否则从新线程呼叫Stop。
ref [devnewsgroups]( http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic50404.aspx )
(新闻组消失)
I'm writing a series of Windows services. I want them to fail if errors are thrown during startup (in OnStart()
method). I had assumed that merely throwing an error in OnStart()
would do this, but I'm finding that instead it "Starts" and presents me with a message stating "The service has started, but is inactive. Is this correct?" (Paraphrase). How do I handle the error so it actually fails to start the service?
if you are running .NET 2.0 or higher, you can use ServiceBase.Stop to stop the service from OnStart. Otherwise call Stop from a new thread.
ref [devnewsgroups] (http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic50404.aspx)
(news group gone)
这篇关于在服务启动时处理异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!