////////////// // Events protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); ping.Enabled = false; ping.Stop(); if (IsConnected) { connection.Send("leave " + ourNickname + " #root"); connection.Dispose(); } }
/// <summary> /// When the kill button is pressed, we gracefully exit the server. /// </summary> private void killbutton_Click(object sender, RoutedEventArgs e) { serverLog.IsEnabled = false; killbutton.IsEnabled = false; new Thread(() => { connection.Dispose(); //You'll notice these calls throughout the code, //when working with WPF, you are not allowed to update the UI directly from anything but //the UI thread. This ensures that the actions we want to take, are taken in the context //of the UI thread. Dispatcher.Invoke(new Action(() => { App.Current.Shutdown(); })); }).Start(); }