简体   繁体   中英

using ServiceController class to find out struck or hung service

I am using ServiceController to get the list of services and its status.

Below is the sample code:

var scServices = ServiceController.GetServices(machineIPOrName).ToList();
var scservice = scServices.FirstOrDefault(i => i.ServiceName.ToUpper().Equals(serviceName.ToUpper()));

Currently it returns if the service is Running, Stopped, StartPending, StopPending , Paused etc. But sometimes even though the service is Running. It will be in a hung up/ struck state, it will not be doing its job. How do i identify if the service is struck or in hunged state ?

If you don't know what the service should be doing, there is no way to check if the service is actually doing it's job. In case you implemented the service yourself, then you could implement some kind of interface to check if it is actually running and not in some kind of halted/endless loop state.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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