0

ServiceController.ExecuteCommand in C# can be used to send custom command to a windows service. Like here - How to send a custom command to a .NET windows Service from .NET code?

ServiceController myService = new ServiceController("MyService");

myService.ExecuteCommand(200);

I also understand that the command number should be between 128 and 256.
So I tried doing the same with both the service name and service display name, but crashed the windows service both times. It doesn't get caught in try catch.
And EventViewer says - "The MyService service terminated unexpectedly. It has done this 1 time(s)."

So my question is - Is it possible for a windows service to call ExecuteCommand within itself to invoke a call to OnCustomCommand() in the same windowsservice?

Thanks-

4

1 回答 1

0

是的。有可能做到这一点。我曾经在 Windows 服务中托管 WCF 服务的地方做过一次,使用 ExecuteCommand 调用主机的方法。如果您需要语法方面的帮助,我想看看您现在正在处理的代码。

于 2014-02-27T11:33:37.490 回答