private void button2_Click(object sender, RoutedEventArgs e) { if (workService != null) { workService.Exit(); workService.CloseServer(); } this.Close(); }
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (System.Windows.MessageBox.Show("确定要退出托盘应用程序吗?", "托盘应用程序", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes) { this.notifyIcon.Visible = false; //停止服务 service.CloseServer(); } else { e.Cancel = true; } }