ANH_WCF_Service.CentralServerMonitor.RemoveServer C# (CSharp) Method

RemoveServer() public method

public RemoveServer ( Server s ) : String
s Server
return String
        public String RemoveServer(Server s)
        {
            Server e = FindServer(s.Process);
            if (e == null) return "Unable to find Server type: " + s.type + " args:" + s.args;

            e.Process.Cancelled -= new EventHandler(pc_Cancelled);
            e.Process.Completed -= new EventHandler(pc_Completed);
            e.Process.Failed -= new System.Threading.ThreadExceptionEventHandler(pc_Failed);
            e.Process.StdErrReceived -= new DataReceivedHandler(pc_StdErrReceived);
            e.Process.StdOutReceived -= new DataReceivedHandler(pc_StdOutReceived);
            e.Process.Cancel(); //TODO: investigate whether cancelandwait or addoutput("q") is more appropriate

            ServerList.Remove(e);

            return "Stopped Server type: " + s.type + " args:" + s.args;
        }

Usage Example

        public String StopServer(ServerType type, String args)
        {
            if (!Authenticated)
            {
                return("You must be Authenticated to perform this task");
            }
            Server s = monitor.FindServer(type, args);

            if (s != null)
            {
                return(monitor.RemoveServer(s));
            }
            else
            {
                return("Unable to find a suitable server to stop. Aborting.");
            }
        }