C#DevExpress - ProgressBar立即填写_DoWork

时间:2015-09-04 22:02:38

标签: c# devexpress

正如标题所说。第一次使用这个控件所以我不确定是什么。

我的OnLoad

bw = new BackgroundWorker();

bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
bw.WorkerReportsProgress = true;

在我的按钮点击事件

// Set props for progress bar
progressBarControl1.EditValue = 1;
progressBarControl1.Properties.Minimum = 0;
// cboTables names is a checkedListBox
progressBarControl1.Properties.Maximum = cboTableNames.CheckedItems.Count;
progressBarControl1.Properties.Step = 1;

// Start BW worker
bw.RunWorkerAsync();

DoWork的

protected void bw_DoWork(object sender, DoWorkEventArgs e)
{
   int counter = 0;
    if (cboTableNames.CheckedItems.Count != 0)
        {
            // Get selected items
            foreach (string item in cboTableNames.CheckedItems)
            {
                // Pass off for archiving
                _myIO.Archive(item, _sqlConn, bw); // I pass bw 
            }
        }
        else
        {
           // Catch if the user tries to submit without table name selection(s)
            MessageBox.Show("You must select a table name to archive.");
        }
    }

现在的目标是在循环浏览每个已检查的项目时不填充进度条。但是在我的IO文件中,我正在向数据库提交项目。目标是反映要插入的每个SQL事务的进度。

// Encapsulated within a loop that is iterating through records and inserting values 
//into the DB. #magic

// For progressbar
pgCounter++;
bw.ReportProgress(pgCounter);

现在奇怪的事情就出现了,就是bw.RunWorkerAsync()将我重定向到DoWork函数的那一刻。发生的那一刻,我的进度条填满了100%。我在这里错过了什么?

此外,除了通常定义BackgroundWorker之外,我还没有看到太多人从其他类调用.ReportProgress。关于正确使用方法的任何提示也将受到赞赏。欢呼声。

0 个答案:

没有答案