backgroundWorker 用法

解决方案 »

  1.   

    private void toolStripButtonUpload_Click(object sender, EventArgs e)
     {
                try
                {
     //其它操作

                    this.backgroundWorkerUpload.RunWorkerAsync(list);
                }
                catch (Exception ex)
                {
                    this.toolStripButtonUpload.Enabled = true;                this.m_Helper.ShowException(ex);
                }
            }        //进度显示
            private void backgroundWorkerUpload_ProgressChanged(object sender, ProgressChangedEventArgs e)
            {
                this.progressBar.Value = e.ProgressPercentage;            this.labTip.Text = string.Format("{0}", Properties.Resources.Message_Executing);
                this.progressBarLabTip.Text = string.Format("{0}%", e.ProgressPercentage);
     
            }        //操作完成  出现错误的时候会调用此方法
            private void backgroundWorkerUpload_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
            {
                this.progressBar.Visible = false;
                this.progressBarLabTip.Visible = false;
                this.labTip.Text = Properties.Resources.Message_LabTipDefaultText;            this.toolStripButtonUpload.Enabled = true;
                this.toolStripButtonUploadCancel.Enabled = false;
            }

            //执行数据操作 不能操作界面上的东西
            private void backgroundWorkerUpload_DoWork(object sender, DoWorkEventArgs e)
            {
                Cursor.Current = Cursors.AppStarting;            try
                {     
                            LogisticsHelper.LogisticsServiceProxy.AddPUPArchive(this.m_Helper.Ticket, info);                        worker.ReportProgress((int)((float)(completed) / (float)total * 100), new ProgressUserState(true, info, null));
                 }
                 catch (Exception ex)
                   {
                           worker.ReportProgress((int)((float)(completed) / (float)total * 100), new ProgressUserState(false, info, ex));
                   }
                        completed++;
                    }
                }
            }
      

  2.   

    谢谢大家! david_anwei(家九) 能给我个完整的例子吗?
      

  3.   

    http://msdn2.microsoft.com/zh-cn/library/system.componentmodel.backgroundworker(VS.80).aspxhttp://idior.cnblogs.com/archive/2005/08/18/217796.html
      

  4.   

    无法显示阿!http://idior.cnblogs.com/archive/2005/08/18/217796.html
      

  5.   


    怪了,刚才还可以的
    Google backgroundWorker 
    例子一大堆