/// <summary> /// 测试连接 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnTestCon_Click(object sender, RoutedEventArgs e) { this.btnTestCon.IsEnabled = false; this.txtConRes.Text = "正在连接……"; //去连接 设备 if (!string.IsNullOrEmpty(txtVisaAddr.Text)) { // SystemHardware.SysHardware.TryConnect(txtVisaAddr.Text); TestConDelegate task = delegate(string connectAddr) { return(this.doTryTest(connectAddr)); }; task.BeginInvoke(txtVisaAddr.Text, EndTryTest, this); } else { MessageBox.Show("VISA地址为空", "消息提示", MessageBoxButton.OK, MessageBoxImage.Information); } }
public void EndTryTest(IAsyncResult ar) { this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { this.btnTestCon.IsEnabled = true; TestConDelegate handler = (TestConDelegate)((AsyncResult)ar).AsyncDelegate; if (handler.EndInvoke(ar)) { this.instrumentInfo.DevInfoState = devState.connect; this.txtConRes.Text = "测试连接成功! "; this.txtConRes.Foreground = new SolidColorBrush(Colors.Green); } else { this.instrumentInfo.DevInfoState = devState.error; this.txtConRes.Text = "测试连接失败! "; this.txtConRes.Foreground = new SolidColorBrush(Colors.Red); } }); }