简体   繁体   English

Windows服务停止的原因

[英]Reasons for windows service to stop

I have designed a windows service in C#, which runs continiously and spawns three threads. 我用C#设计了一个Windows服务,该服务连续运行并产生三个线程。 The first thread runs every 15 sec. 第一个线程每15秒运行一次。 The second thread runs every min. 第二个线程每分钟运行一次。 And the thirs runs only once. 和干渴只跑一次。

My problem is that this windows service somehow just stops after few days.There is nothing logged in the eventlog on the day of stopping.And it didn't write anything in the logging file. 我的问题是,几天后,该Windows服务就以某种方式停止了。停止的那一天,事件日志中没有任何记录,并且没有在记录文件中写入任何内容。

I want to know what are the various reasons for a windows service to stop abruptly. 我想知道Windows服务突然停止的各种原因是什么。 And this service is not on my DEV box, it is on QA server. 而且此服务不在我的DEV机器上,而是在QA服务器上。

hope it make sense! 希望有道理!

You probably have an unhandled exception on one of your threads- since .NET 2.0, unhandled exceptions will take down the process abruptly like this. 您可能在一个线程上有未处理的异常-自.NET 2.0起,未处理的异常将像这样突然终止进程。 Make sure the top of stack for anything you run on a thread has a catch block to handle errors (log, swallow, marshal to another thread, whatever). 确保在线程上运行的所有对象的堆栈顶部都有一个catch块来处理错误(日志,吞咽,编组到另一个线程,无论如何)。 You can temporarily prevent this behavior (eg, revert to pre-.NET 2.0 behavior) by adding the following to your service's .exe.config file: 通过将以下内容添加到服务的.exe.config文件中,可以暂时防止此行为(例如,还原到.NET 2.0之前的行为):

<configuration>
  <runtime>
    <legacyUnhandledExceptionPolicy enabled="1" />
  </runtime>
</configuration>

but don't rely on it- it may be removed in a future .NET release (haven't checked 4.0- it may already be gone). 但不要依赖它-它可能会在将来的.NET版本中删除(尚未检查4.0-它可能已经不存在了)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM