Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to link progress change event to progress bar
    primarykey
    data
    text
    <p>I have windows form application that run a a class method by BackgroundWorker.</p> <p>I would like to add the windows form a progress bar to show the progress.</p> <p>in the class method I have a foreach loop so I would like each loop to send the form event </p> <p>with the current percentage.</p> <p>this is what i do :</p> <pre><code>public partial class Form1 : Form { Parsser inst; public Form1() { InitializeComponent(); inst = new Parsser(); backgroundWorker1.WorkerReportsProgress = true; backgroundWorker1.WorkerSupportsCancellation = true; } private void button2_Click(object sender, EventArgs e) { if (this.textBox1 != null &amp; this.textBox2 != null) { if (backgroundWorker1.IsBusy != true) { // Start the asynchronous operation. backgroundWorker1.RunWorkerAsync(); } } } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { inst.init(this.textBox1.Text, this.textBox2.Text); inst.ParseTheFile(); System.Windows.Forms.MessageBox.Show("Parsing finish successfully"); } private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { this.progressBar1.Value = e.ProgressPercentage; } } } </code></pre> <p>`</p> <p>and in the class i do this-</p> <pre><code>public Parsser() { bgReports = new BackgroundWorker(); bgReports.WorkerReportsProgress = true; } public void ParseTheFile() { Lines = File.ReadAllLines(FilePath); this.size = Lines.Length; foreach (string line in Lines) { bgReports.ReportProgress(allreadtchecked/size); </code></pre> <p>from some reason it dont work any idea?</p>
    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. 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