public override int?OverrideAfterHandlingArgumentsBeforeRun(string[] remainingArguments) { // If start, make sure started. if (Start && SocketHelpers.IsTCPPortAvailable(EnvironmentDetails.ServiceDaemonPort)) { new Admin(EnvironmentDetails, Client) { Start = true }.Run(new string[] { }); while (SocketHelpers.IsTCPPortAvailable(EnvironmentDetails.ServiceDaemonPort)) { Thread.Sleep(500); } } // Before dying, send stop request. AppDomain.CurrentDomain.ProcessExit += (sender, e) => { if (Kill && Client.Get(new TorrentsListRequest()).Count() == 0) { new Admin(EnvironmentDetails, Client) { Stop = true } } .Run(new string[] {}); };