Restart Windows Service when faulted

狂风中的少年 提交于 2019-12-06 16:16:21

问题


We have an windows service written in .net, that is hosting WCF service. My question is, Is it possible to monitor and restart service on any fault, in other world I want my service to be restarted automaticaly on any fault.
Thanks a lot


回答1:


Start / Control Panel / Services / right-click your service / Properties / First failure : restart the service / Second failure : restart the service / Subsequent failure : restart the service.

Should do it.




回答2:


Go into the service manager in the OS, right-click your service and choose properties. There you'll find a recovery tab which lets you define behavior on crashes.




回答3:


Within single windows service there can be multiple WCF services. You can handle Faulted event of the ServiceHost class for individual WCF service and re-initialize it.




回答4:


I think you should think about the design of your service. It should be a host to the wcf process. You could make 3 threads:

  • Main thread (only stops on v FATAL error)

  • ExceptionHandler thread (handles "expected" exceptions and does logging and takes care of the WCFHost thread dying)

  • WCFHost thread (Hosts the WCF Service and can die as often as it likes the ExceptionHandler can take care of this now.)




回答5:


You could write another service like a watcher service that will monitor this core service & will re-start it when stopped. However, nothing can be done if the watcher service is stopped.



来源:https://stackoverflow.com/questions/973961/restart-windows-service-when-faulted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!