views:

28

answers:

2

Hi,

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, Suspended 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.

+2  A: 

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.

Richard
Ok got it. But I thought that it would be possible to have something similar to the "responsiveness" status of an application on the windows task manager (ctrl-alt-del). So instead of going to the functionnal level, staying at the system/process level.
Amokrane
+2  A: 

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.

Lasse V. Karlsen
Never worked with IPCs on .NET. This is the occasion :)
Amokrane