wcf windows 服务恢复程序

wcf windows service recovery program

我有一个托管 WCF 服务器的 windows 服务。 我使用 "sc config...." 和 "sc failure..." 来设置以下属性: 1)登录凭据 - 本地用户 2) 恢复 - 重新启动前 2 次失败的服务,然后 运行 一个程序(.bat 或 .cmd)

我尝试用几种使服务崩溃的方法对其进行测试,但没有一种方法会影响恢复。 我尝试通过任务管理器 taskkil,在代码中抛出异常,除以零...

没有任何反应 - 没有重新启动,也没有 运行 程序。 有什么想法吗?

我敢打赌,wcf 服务是在包含服务的线程中产生的,并且主线程不会像您期望的那样因子抛出的异常而退出。

See this article.

Since this exception is being thrown on a different thread than the main thread, I need to subscribe to the AppDomain’s UnhandledException event. If I don’t do this the thread will just die silently and the service will continue to run, which is not what I want.