private void CmdConnect_Click(object sender, EventArgs e) { if (_connected) // Disconnect { if (_client == null) { _connected = false; UpdateButtons(); return; } _client.CloseClientAsync(); } else // Connect { if (int.TryParse(txtPort.Text, out int port)) { if (!IsUriValid(txtServer.Text, port)) { return; } _client = new WsClient(txtServer.Text, int.Parse(txtPort.Text)); _client.ConnectionStateChanged += Client_ConnectionStateChanged; _client.MessageReceived += Client_MessageReceived; _client.ConnectionError += Client_ConnectionError; } else { MessageBox.Show(this, LocalizedResourceHelper.GetLocalizedText(rm, "PortMustBeAnInteger", "Port must be an Integer"), LocalizedResourceHelper.GetLocalizedText(rm, "Error", "Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } UpdateButtons(); }