Question

In .NET, the ServiceController class allows you to send a custom command to a service using the ExecuteCommand method.

I would like to be able to query the service for its status (a custom notion of status, not the 'Started/Stopped' variety). I was hoping it would be straightforward to make a call to the service using something similar to ExecuteCommand and get a return value indicating the status. Is there something in ServiceController that would enable me to do this?

Assuming not, I guess I have to use some kind of external inter-process communication technique (e.g. service writes its status to a database, or to a message queue). What would you recommend for simplicity?

Était-ce utile?

La solution

There certainly isn't a way in ServiceController. Leaving WCF as presumably the best option. Tutorials here: http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication

Autres conseils

Windows offers many means of inter process communication (IPC). @David is right, ServiceControllers cannot perform this action, and he was good to point you to WCF, its a foundation that comes readymade with IPC capabilities. Using IPC you could coordinate your service and your application after an ExecuteCommand call.

If your not looking to go as far as WCF you could implement a pipe (anonymous pipe seems right for this case) or use windows sockets.

Check out this link from MSDN on IPC, it's a great trailhead for the multiple avenues you could take.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top