コード例 #1
0
 void _backWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     //如果是正常完成,进入安装界面
     if (_isNormal)
     {
         this.Hide();
         MainWindow mw = new MainWindow();
         mw.ShowDialog();
     }
     NamedPipeClientHelper.Close();
     this.Close();
 }
コード例 #2
0
 void _backWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         NamedPipeClientHelper.Connect();
         //获取管道服务发送的数据
         string content = NamedPipeClientHelper.Read();
         while (!string.IsNullOrEmpty(content) && content != "End")
         {
             //如果是进度信息
             if (content.Contains("/"))
             {
                 string[] proArray = content.Split('/');
                 //设置进度条信息
                 this.Dispatcher.Invoke(new Action(() =>
                 {
                     double curProValue   = double.Parse(proArray[0]);
                     double totalProValue = double.Parse(proArray[1]);
                     double rate          = (curProValue / totalProValue) * 100;
                     proBar.Maximum       = totalProValue;
                     proBar.Value         = curProValue;
                     tbProInfo.Text       = string.Format("{0}%", rate.ToString("f0"));
                 }));
             }
             //如果是包信息
             else
             {
                 tbBagInfo.Dispatcher.Invoke(new Action(() => tbBagInfo.Text = content));
             }
             content   = NamedPipeClientHelper.Read();
             _isNormal = true;
         }
     }
     catch (Exception ex)
     {
         _isNormal = false;
         _loger.Error("_backWorker_DoWork()方法:" + ex.Message);
         MessageBox.Show("获取下载数据出错!");
     }
     finally
     {
         //NamedPipeClientHelper.Close();
     }
 }