Note that there are some explanatory texts on larger screens.

plurals
  1. POC# WinForm BackgroundWorker not Updating Processbar
    text
    copied!<p>I am having a little trouble with getting the backgroundworker to update my progress bar. I was using a tutorial online as an example, but my code is not working. I did some digging on this site and I can't find any kind of solution. I am new to the backgroundworker/progress thing. So I don't understand it fully.</p> <p>Just to set things up: I have a main form (FORM 1) that opens another (FORM 3) with the progress bar and a status label. </p> <p>my Form 3 code as is:</p> <pre><code>public string Message { set { lblMessage.Text = value; } } public int ProgressValue { set { progressBar1.Value = value; } } public Form3() { InitializeComponent(); } </code></pre> <p>My Form 1 Partial Code:</p> <pre><code>private void btnImport_Click(object sender, EventArgs e) { if (backgroundWorker1.IsBusy != true) { if (MessageBox.Show("Are you sure you want to import " + cbTableNames.SelectedValue.ToString().TrimEnd('$') + " into " + _db, "Confirm to Import", MessageBoxButtons.YesNo) == DialogResult.Yes) { alert = new Form3(); //Created at beginning alert.Show(); backgroundWorker1.RunWorkerAsync(); } } } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; int count = 0 foreach(DataRow row in DatatableData.Rows) { /*... Do Stuff ... */ count++; double formula = count / _totalRecords; int percent = Convert.ToInt32(Math.Floor(formula)) * 10; worker.ReportProgress(percent, string.Format("Completed record {0} out of " + _totalRecords, count)); } } private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { alert.Message = (String) e.UserState; alert.ProgressValue = e.ProgressPercentage; } private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { alert.Close(); } </code></pre> <p>So. The problem is its not updating anything. The progress bar nor the label is updating. Can someone point me in the write direction or have a suggestion?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload