private void _ConnectAsync(string ip, int port) { var resultTask = _Connecter.Connect(new IPEndPoint(IPAddress.Parse(ip), port)); var result = resultTask.Result; Command.Unregister("Disconnect"); if (result) { Command.Register("Disconnect", () => _Connecter.Disconnect().Wait()); } }