I have an a windows form application that use one class (its name is Parser)
this form has a button and when i click on the windows form application button it call one of the parser class method .
this method simply read text file line after line and write each line to separate file…
i would like to add a progress bar to the form in order to show the progress( it is a very large file )
any idea how to do that? I have in the Parse class 2 property one for the number of line in the file and the second how much lines already checked.
here is my button2_Click function
private void button2_Click(object sender, EventArgs e)
{
if (this.textBox1 != null & this.textBox2 != null)
{
inst.init(this.textBox1.Text, this.textBox2.Text);
//this.progressBar1.Show();
inst.ParseTheFile();
System.Windows.Forms.MessageBox.Show("Parsing finish successfully");
}
}
You could do:
In the example above, it simply creates a background thread in order not to block the UI thread, until the
Invokemethod is called.The
Invokemethod is necessary, in order to manipulate with aControlthat the current thread isn’t the owner of. It takes a delegate, and runs this delegate on the thread that owns theControl.You could even go as far, as making the
foreachloop parallel, if it’s a time consuming task to parse the lines. An example: