private void _Click(object sender, RoutedEventArgs e) { var tag = (e.OriginalSource as Button)?.Tag as string; if (tag == null) { return; } if (tag == "exit") { LinkModule.Shutdown(); Application.Current.MainWindow.Close(); } else if (tag == "out") { var mai = Application.Current.MainWindow as Entrance; if (mai == null) { return; } LinkModule.Shutdown(); ProfileModule.Shutdown(); mai.frame.Navigate(new Connection()); } }
private async void _Click(object sender, RoutedEventArgs e) { async void _Refresh() { uiRefreshButton.IsEnabled = false; var lst = await Task.Run(HostModule.Refresh); foreach (var inf in lst) { int idx = _hosts.IndexOf(inf); if (idx < 0) { _hosts.Add(inf); } else { _hosts[idx] = inf; } } uiRefreshButton.IsEnabled = true; } var src = (Button)e.OriginalSource; if (src == uiBrowserButton) { uiBrowserButton.Visibility = Visibility.Collapsed; uiRefreshButton.Visibility = uiListGrid.Visibility = Visibility.Visible; _Refresh(); return; } else if (src == uiRefreshButton) { _hosts.Clear(); _Refresh(); return; } else if (src == uiConnectButton) { uiConnectButton.IsEnabled = false; try { var uid = int.Parse(uiIdBox.Text); var pot = int.Parse(uiPortBox.Text); var hos = uiHostBox.Text; var add = IPAddress.TryParse(hos, out var hst); if (add == false) { hst = Dns.GetHostEntry(hos).AddressList.First(r => r.AddressFamily == AddressFamily.InterNetwork); } var iep = new IPEndPoint(hst, pot); // 放弃等待该方法返回的任务 var _ = await LinkModule.Start(uid, iep); HostModule.Name = hos; HostModule.Port = pot; NavigationService.Navigate(new PageFrame()); } catch (Exception ex) { Log.Error(ex); Entrance.ShowError("连接失败", ex); } uiConnectButton.IsEnabled = true; } }