コード例 #1
0
        private void IPC_PasswordChanged(object sender, RoutedEventArgs e)
        {
            PasswordBox ps = (PasswordBox)sender;

            if (ps != null)
            {
                if (ipcs_settings.SelectedIndex != -1)
                {
                    IPCSettings drw = ipcs_settings.CurrentItem as IPCSettings;
                    if (drw != null)
                    {
                        drw.PW           = ps.Password;
                        btn_ok.IsEnabled = true;
                    }
                }
            }
        }
コード例 #2
0
        private void ScanDev_Completed(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                List <string> res = (List <string>)e.Result;
                if (res.Count > 0)
                {
                    ipcs_settings.ItemsSource = null;
                    settings.Clear();

                    for (int i = 0; i < res.Count; i++)
                    {
                        if (i < 2)
                        {
                            IPCSettings ipcs = new IPCSettings(true, res[i],
                                                               SystemSettings.DefaultPort, "通道" + (i + 1), "", "");
                            settings.Add(ipcs);
                        }
                        else
                        {
                            IPCSettings ipcs = new IPCSettings(false, res[i],
                                                               SystemSettings.DefaultPort, "通道" + (i + 1), "", "");
                            settings.Add(ipcs);
                        }
                    }
                    ipcs_settings.ItemsSource = settings;
                    ipcs_settings.Items.Refresh();
                    btn_ok.IsEnabled = true;
                }
                else
                {
                    LogManager.Insert(this, "ScanDev_Completed", "未扫描到任何设备!");
                }
            }
            catch (Exception ex)
            {
                string errMsg = "";
                if (ex.InnerException != null)
                {
                    errMsg = ex.Message + "(" + ex.InnerException.Message + ")";
                }
                else
                {
                    errMsg = ex.Message;
                }
                LogManager.Insert(this, "ScanDev_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();
                }
            }
        }