.Net(C#)服务无法启动 [英] .Net (C#) Service Fails To Start

查看:83
本文介绍了.Net(C#)服务无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多用C#(。Net)开发的服务,而且它们大部分工作都很好。最近有人报告说ipon

occassion(最初很少,但是在某些系统上更频繁地花了b / b
),在启动后立即在事件日志中有一个条目$>
表示服务在30,000毫秒后无法启动。

通常在启动后手动尝试时启动。


我已经检测到在

main()执行期间以及OnStart()执行期间将条目写入事件日志的代码 - 但是当

失败时,没有事件日志中的条目来自服务代码!


尝试将服务作为控制台应用程序启动似乎总是成功。有趣的是,作为控制台应用程序启动的速度比启动服务快10倍b $ b!在任何情况下,服务

都没有正确加载,时间超过500毫秒!


我检查过并且没有标记该服务的依赖项。是吗?b $ b可能.Net当时不可用且服务不能执行
吗?


如何定义编译时的任何依赖? ServiceInstaller

允许我定义一个依赖的服务列表,但是没有

似乎是对其他对象的依赖。似乎也没有任何我可以等待的.Net服务。


有没有人对我的服务可能无法加载的原因有任何想法,但

仅在启动时?

/ LogToConsole = false开关设置来自我的

安装服务?如何将此更改为true,以及对我的服务有什么影响?


-ken

I have a number of services developed in C# (.Net), and they have been
working fine for the most part. Recently someone reported that ipon
occassion (originally rarely, but more frequently on some systems of
late), there is an entry in the Event Log immediately after a boot
indicating that the service failed to start after 30,000 milliseconds.
Usually it starts fine when attempting manually after the boot.

I instrumented the code to write entries to the Event Log during its
main() execution as well as during the OnStart() execution -- but when
it fails, there are no entries in the Event Log from the service code!

Attempting to launch the service as a console application always seems
to succeed. Interestingly, launching as a console application is about
10 times faster than starting the service! In no case that the service
loaded properly did the time pass the 500 milliseond duration!

I checked and there are no dependencies marked for the service. Is it
possible that .Net is not available at that time and the service cannot
execute?

How can I define any dependencies at compile time? The ServiceInstaller
permits me to define a list of services to depend on, but there does not
seem to be any dependency on other objects. Nor does there appear to be
any .Net service on which I could wait.

Does anyone have any ideas on why my service may be failing to load, but
only at boot time?

Where does the /LogToConsole=false switch setting come from on my
installed services? How do I change this to true, and what effect would
that have on my service?

-ken

推荐答案

如果所有其他方法都失败,你可以尝试一种技术是在你的OnStart()方法的所有代码周围插入一个try / catch块

并显示任何

消息框中的错误。请注意,这将要求您的服务具有与桌面交互

桌面允许。或者,您可以将消息写入磁盘上已知的

文件。


-

Jared Parsons [MSFT]
ja******@online.microsoft.com
http://blogs.msdn.com/jaredpar

" This发布是按原样提供的。没有保证,也没有授予任何权利

Ken Allen" <柯****** @ sympatico.ca>在消息中写道

新闻:eV ************** @ TK2MSFTNGP15.phx.gbl ...
One technique you could try if all else fails is to insert a try/catch block
around all of the code in your OnStart() method and show any errors in a
message box. Note this will require your service to have the "Interact With
Desktop" permission. Alternately, you could write the message to a known
file on disk.

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
http://blogs.msdn.com/jaredpar
"This posting is provided "AS IS" with no warranties, and confers no rights"
"Ken Allen" <ke******@sympatico.ca> wrote in message
news:eV**************@TK2MSFTNGP15.phx.gbl...
我有一些用C#(。Net)开发的服务,它们在大多数情况下工作正常。最近有人报告了igo
occassion(最初很少,但最近在一些系统上更频繁),
在启动后立即在事件日志中有一个条目表明服务未能通过在30,000毫秒后开始。通常在启动后手动尝试时它会启动。

我检测代码在执行
main()期间以及在OnStart期间将事件写入事件日志()执行 - 但是当它失败时,服务代码中的事件日志中没有条目!

试图将服务作为控制台应用程序启动似乎总是
成功。有趣的是,作为控制台应用程序启动的速度比启动服务快10/5倍!在任何情况下加载的服务都没有正确地完成时间超过500毫秒!

我检查了并且没有标记为服务的依赖项。是否有可能.Net当时不可用且服务无法执行?

如何在编译时定义任何依赖项? ServiceInstaller
允许我定义要依赖的服务列表,但似乎没有依赖于其他对象。似乎也没有任何我可以等待的.Net服务。

有没有人知道为什么我的服务可能无法加载,但
只在启动时间?

/ LogToConsole = false开关设置来自我的
安装服务?如何将此更改为true,以及对我的服务有何影响?

-ken
I have a number of services developed in C# (.Net), and they have been
working fine for the most part. Recently someone reported that ipon
occassion (originally rarely, but more frequently on some systems of late),
there is an entry in the Event Log immediately after a boot indicating that
the service failed to start after 30,000 milliseconds. Usually it starts
fine when attempting manually after the boot.

I instrumented the code to write entries to the Event Log during its
main() execution as well as during the OnStart() execution -- but when it
fails, there are no entries in the Event Log from the service code!

Attempting to launch the service as a console application always seems to
succeed. Interestingly, launching as a console application is about 10
times faster than starting the service! In no case that the service loaded
properly did the time pass the 500 milliseond duration!

I checked and there are no dependencies marked for the service. Is it
possible that .Net is not available at that time and the service cannot
execute?

How can I define any dependencies at compile time? The ServiceInstaller
permits me to define a list of services to depend on, but there does not
seem to be any dependency on other objects. Nor does there appear to be
any .Net service on which I could wait.

Does anyone have any ideas on why my service may be failing to load, but
only at boot time?

Where does the /LogToConsole=false switch setting come from on my
installed services? How do I change this to true, and what effect would
that have on my service?

-ken



但问题是main()例程中的任何代码(在$ OnStart()之前都必须执行),在这种情况下产生输出

。这就好像该程序无法启动 - 但它确实启动了,因为一旦系统
允许登录,它就会出现在服务列表中!<
-ken


Jared Parsons [MSFT]写道:
But the problem is that none of the code in the main() routine, which
must execute before the OnStart(), is producing output in this case
either. It is just as if the program was not able to launch -- but it
does launch since it appears in the list of services once the system
permits a logon!

-ken

Jared Parsons [MSFT] wrote:
如果其他所有方法都失败,你可以尝试一种技巧在OnStart()方法的所有代码周围插入一个try / catch块,并在
消息框中显示任何错误。请注意,这将要求您的服务具有与桌面交互和与桌面交互。允许。或者,您可以将消息写入磁盘上的已知
文件。
One technique you could try if all else fails is to insert a try/catch block
around all of the code in your OnStart() method and show any errors in a
message box. Note this will require your service to have the "Interact With
Desktop" permission. Alternately, you could write the message to a known
file on disk.





" Ken Allen" <柯****** @ sympatico.ca>在消息中写道

新闻:OE ************** @ TK2MSFTNGP09.phx.gbl ...

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
但问题是main()例程中的任何代码都不能在OnStart()之前执行,在这种情况下也会生成输出。它就好像该程序无法启动 - 但它确实启动了
,因为一旦系统允许登录它就会出现在服务列表中!

- kared

Jared Parsons [MSFT]写道:
But the problem is that none of the code in the main() routine, which must
execute before the OnStart(), is producing output in this case either. It
is just as if the program was not able to launch -- but it does launch
since it appears in the list of services once the system permits a logon!

-ken

Jared Parsons [MSFT] wrote:
如果所有其他方法都失败,你可以尝试一种技术是在所有代码周围插入一个try / catch
块在您的OnStart()方法中,并在消息框中显示任何错误。请注意,这将要求您的服务具有
与桌面交互。允许。或者,您可以将
消息写入磁盘上的已知文件。
One technique you could try if all else fails is to insert a try/catch
block around all of the code in your OnStart() method and show any errors
in a message box. Note this will require your service to have the
"Interact With Desktop" permission. Alternately, you could write the
message to a known file on disk.




您在OnStart中究竟做了什么?您是冒充还是

访问网络资源?


Willy。



What exactly are you doing in your OnStart? Are you Impersonating or are you
accessing network resources?

Willy.


这篇关于.Net(C#)服务无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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