As in the following link, one can stop, start, and \"stop, then start\" a service using C# code.
http://www.csharp-examples.net/restart-windows-service/
I ha
The usual means of communicating with external processes in windows are:
The first two have been exposed as WCF so that is the way to go. Third one does not seem relevant to your situation and is old.
If you need to run your commands from the same machine you can use named pipes but hardening has made it very difficult and troublesome. Otherwise use WCF's TCP named binding.
You can send "commands" to a service using ServiceController.ExecuteCommand:
const int SmartRestart = 222;
var service = new System.ServiceProcess.ServiceController("MyService");
service.ExecuteCommand(SmartRestart);
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
You'll need to add a Reference to the System.ServiceProcess.dll assembly.
The service can react to the command by overriding ServiceBase.OnCustomCommand:
protected override void OnCustomCommand(int command)
{
if (command == SmartRestart)
{
// ...
}
}