How to call a windowsservice ExecuteCommand to excute a OnCustomCommand on itself? RRS feed

  • Question

  • ServiceController.ExecuteCommand in C# can be used to send custom command to a windows service. Like here -

    ServiceController myService = new ServiceController("MyService");


    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?


    Wednesday, March 27, 2013 3:45 AM


  • if you need to invoke the function within the assembly, i don't see you need to invoke through the customcommand.

    just move/duplicate your customcommand mtd to another protected/internal method, should serve the same purpose.

    Wednesday, March 27, 2013 4:39 AM