private void button1_Click(object sender, RoutedEventArgs e) { string username = usernameBox.Text; if (username.Equals("")) { MessageBox.Show("Error - You must enter a username.", "Please enter a username."); return; } try { parseIPString(ref ip, ref port, serverBox.Text); if (ip == null) { throw new ArgumentException(); } } catch (Exception) { MessageBox.Show("Error - cannot read ip address. Format is <name>,<ip>:<port>.", "IP Error"); return; } settings.addUsername(username); /* * ChatWindow wind = new ChatWindow(); * wind.Closed += connectionClosed; * wind.Show(); * wind.Start(ip, port, username); */ this.Visibility = Visibility.Hidden; k.BeginNewConnection(ip, port, username); k.connectionFailed += () => Application.Current.Dispatcher.BeginInvoke(new Action(() => Show())); k.connectionFailed += () => Application.Current.Dispatcher.BeginInvoke(new Action(() => k.closeAllWindows())); this.Hide(); }