Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

adding progress bar

Posted on 2011-09-25
2
Medium Priority
?
392 Views
Last Modified: 2012-05-12
Hi

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"); 
            }
        }

Open in new window

0
Comment
Question by:dpatel_team
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 36595417
You need to call ParseTheFile() from a different thread, or use a BackgroundWorker() control.

A good technique would be to make the Parser() class raise a custom Progress() event that you subscribe to.  When that event is received you update the Form via delegates/BeginInvoke() or use the ReportProgress() method of the BackgroundWorker().
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question