private void BtnConnect_Click(object sender, EventArgs e) { try { OpenSelectedService(null); ListServices.Items.Clear(); if (sender == BtnConnect) { m_manager.Connect(string.IsNullOrEmpty(BoxCompName.Text) ? null : BoxCompName.Text); m_manager.GetServices(out IEnumService services); while (true) { services.Next(out string name, out string display); if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(display)) { break; } ListServices.Items.Add(new ServiceItem(name, display)); } if (ListServices.Items.Count > 0) { ListServices.SetSelected(0, true); } m_connected = true; } else { m_manager.Disconnect(); m_connected = false; UpdateServiceControls(); } UpdateServiceInfo(); } catch (Exception exc) { ShowError($"Unable to connect SCM on computer {BoxCompName.Text}.", exc.Message); } finally { UpdateConnectButtons(); UpdateServiceInfo(); UpdateServiceControls(); ListServices.Focus(); } }