简体   繁体   中英

Communicate with a Windows Service using ServiceController class

I have a windows services project consisting of two services, service1 and service2. How can we communicate between the two services? For example, how can we have have service2 started by service1? Can I use the ServiceController class to do this? What would you suggest to do this?

The ServiceController class includes an ExecuteCommand methods that takes an int. Your two services could therefore communicate by sending ExecuteCommand messages to each other if you can get away with very limited parameters.

However, as the other poster comments, WCF may be a better answer. You can create named pipes or use HTTP between the two services. Two good tutorial pages can be found below.

Basic WCF Tutorial with examples

More complex WCF, if you wanted to 'fake' delegates for example

Hope that helps.

If "comunication" you mean just to start and stop Service2, than yes, ServiceController should be used.

If you need other type of comunication, like sending some data from one to another,than ServiceController will not help, you should use WCF

Hope this helps

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