开发者

How to test the reactivity of a Windows Service?

I'm programming a monitoring application that needs to display the state of several windows services. In the current version, I can know whether a service is Running, Stopped, Suspe开发者_如何学Gonded or in one of the pending states. That's good, but I'm wondering if there is a way to test if a service is actually responding? I guess it can be in a running state but not responding at all!

I am using the ServiceController class from System.ServiceProcess. Do you think that if a service is not responding, the ServiceController.Status would return an exception?

How would you approach the problem?

Thanks

EDIT Seems that: ServiceController.Status can return 2 types of exceptions:

System.ComponentModel.Win32Exception: An error occurred when accessing a system API.
System.InvalidOperationException: The service does not exist as an installed service.

Nothing about reactivity.


This might be obvious, but have you tried talking to the service?

There's no common way to talk to a service, so there is no way Windows can interrogate whether the service is still responding as normal. It is perfectly normal for a service to go into a complete sleep waiting for external I/O to happen, and thus Windows would not get a response while the service is actually alive and functioning exactly as designed.

The only way is to actually send a request to it, and wait for the response, and for that you need some inter-process communication channel, like:

  • Network
  • Named pipes
  • Messages

Basically, if you need to determine if a service is able to respond, you need to check if it is responding.


The service controller types and APIs can only provide information on the basis of the service's response to those APIs.

E.g. you can create a service which responds to those APIs correctly, but provides no functionality on even numbered hours.

In the end you need to define "responsive" in terms of the services functionality (e.g. a batch processor is processing batches) and provide a mechanism (A2A API, WMI, Performance Counters) to surface this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜