Send string commands or bytes to a Windows Service? (When running)

后端 未结 4 1377
予麋鹿
予麋鹿 2021-02-10 22:41

Is there any way to give string or byte array commands to a Windows Service? (When running)

4条回答
  •  离开以前
    2021-02-10 22:53

    As @Derrick mentioned, .Start() can be used, which can also accept arguments that can be passed to the service (but this is at run-time not during execution).

    If you're looking to pass information while the service is executing you have a few options:

    1. Create a service listener and use endpoints to communicate (WCF, Named pipes, etc)
    2. Use windows' built in OnCustomCommand but then you're limited to an integer.
    3. Windows has some information on dynamically configuring a windows service but looks like configuration file changes and taking advantage of OnConfigurationChange (if that's an option)

    There are inevitably more, but those are what I can think of off the top of my head.

提交回复
热议问题