private void ConnectAP_Completed(object sender, RunWorkerCompletedEventArgs e) { try { object[] res = (object[])e.Result; if ((bool)res[0])//连接成功 { List <string> ips = GeneralMethod.GetLocalIPS(); localIP = ips[0]; ip_begin_h.Text = ips[0].Substring(0, ips[0].LastIndexOf('.') + 1); ip_end_h.Text = ips[0].Substring(0, ips[0].LastIndexOf('.') + 1); btn_scan.IsEnabled = true; btn_connect.Content = "网络已连接"; btn_connect.IsEnabled = false; btn_ok.IsEnabled = true; btn_connect.Foreground = new SolidColorBrush(Colors.Green); } else//连接失败 { LogManager.Insert(this, "ConnectAP_Completed", res[1].ToString()); MsgBox.ShowV2(res[1].ToString(), MsgBoxType.Error, this); btn_scan.IsEnabled = false; btn_ok.IsEnabled = false; btn_connect.IsEnabled = true; } } catch (Exception ex) { string errMsg = ""; if (ex.InnerException != null) { errMsg = ex.Message + "(" + ex.InnerException.Message + ")"; } else { errMsg = ex.Message; } LogManager.Insert(this, "ConnectAP_Completed", errMsg); MsgBox.ShowV2(errMsg, MsgBoxType.Error, this); } finally { if (sender != null)//捕获异常后手动关闭线程 { BackgroundWorker worker = sender as BackgroundWorker; if (worker.WorkerSupportsCancellation && !worker.CancellationPending) { worker.CancelAsync(); } worker.Dispose(); } if (waitBox != null) { waitBox.Close(); } } }
private void StopWorker() { _waitingBox.Close(); _isOpeningWaitingBox = false; }
private void StopWorker() { _waitingBox.Close(); }