/// <summary> /// 识别设备 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDevID_Click(object sender, RoutedEventArgs e) { this.btnDevID.IsEnabled = false; this.txtIdetn.Text = "正在识别……"; bool idResult; // string idInfo; if (!string.IsNullOrEmpty(txtVisaAddr.Text)) { TryIdentifyDelegate tryIdentifyDelegate = doTryIdentify; tryIdentifyDelegate.BeginInvoke(txtVisaAddr.Text, out idResult, EndTryIdentify, this); } else { MessageBox.Show("VISA地址为空", "消息提示", MessageBoxButton.OK, MessageBoxImage.Information); } }
protected void EndTryIdentify(IAsyncResult ar) { this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { this.btnDevID.IsEnabled = true; bool idResult; string idInfo; TryIdentifyDelegate handler = (TryIdentifyDelegate)((AsyncResult)ar).AsyncDelegate; idInfo = handler.EndInvoke(out idResult, ar); if (idResult) { this.txtIdetn.Text = idInfo; this.txtIdetn.Foreground = new SolidColorBrush(Colors.Green); } else { this.txtIdetn.Text = "识别失败!" + idInfo; this.txtIdetn.Foreground = new SolidColorBrush(Colors.Red); } }); }