Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, you actually <em>can</em> update that status label in a thread-safe manner using the <code>ProgressChanged</code> event you're already using; <code>BackgroundWorker.ReportProgress</code> has an overload that takes an <code>object</code> parameter to pass additional information for just this purpose.</p> <p>Secondly, <em>if</em> the problem is that you're trying to set your progress bar's value beyond the maximum, it may be that your hard-coded value of 100 does not correspond to the progress bar's <code>Maximum</code> property (though this seems unlikely since 100 is the default value, I believe).</p> <p>So my suggested changes to your code would be:</p> <pre><code>private void worker_DoWork(object sender, DoWorkEventArgs e) { for (int i = 0; i &lt; allFiles.Length; i++) { localSize += allFiles[i].Length; localFiles++; // this you can pass to ReportProgress string statusText = allFiles[i].Name; int progressPercentage = (100 * i) / allFiles.Length; worker.ReportProgress(progressPercentage, statusText); } } private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { // now that this is being done here, it is thread-safe string statusText = e.UserState as string; if (!string.IsNullOrEmpty(statusText)) { toolStripStatusLabel.Text = statusText; } // your progress should be capped at the ProgressBar's Maximum, // rather than 100 int progress = e.ProgressPercentage; int maxProgress = fileRetrievalProgressBar.Maximum; fileRetrievalProgressBar.Value = Math.Min(progress, maxProgress); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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