I found a tutorial that uses Topshelf to create a service and run it within Visual Studio. It worked, because the service did not need any input from outside; it just kept doing something on a timer. But if I create a service, using Topshelf, that accepts commands from another process, and run it within Visual Studio, is there anyway to connect to the service from another process? Or is it impossible?
For example, if the service has this,
public void OnCustomCommand(int command)
{
Console.WriteLine("Got " + command);
and I ran the service in Visual Studio. Can I connect to the service from another process using a code like this?
ServiceController sc = new ServiceController("YOURServiceName", Environment.MachineName);
ServiceControllerPermission scp = new ServiceControllerPermission(ServiceControllerPermissionAccess.Control, Environment.MachineName, "YOURServiceName");//this will grant permission to access the Service
scp.Assert();
sc.Refresh();
sc.ExecuteCommand((int)YourMethods.methodX);