private void ConnectButton_OnClick(object sender, RoutedEventArgs e) { try { client.SwitchState(); if (client.IsActive) { client.SetUsername(Username.Text); } } catch (Exception exception) { MessageBox.Show(exception.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } }