private void Form1_Load(object sender, EventArgs e)
{
// Start the BackgroundWorker
// Creates thread and DoWork method begins.
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 1; i <= 100; i++)
{
// Wait 100 ms at each iteration in order to see the progress
Thread.Sleep(100);
// Report Progresss
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.ReportProgress(i);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
// Change the value of the ProgressBar to the BackgroundWorker progress.
progressBar1.Value = e.ProgressPercentage;
// Set the text of the titlebar
this.Text = e.ProgressPercentage.ToString();
}
but this just adds to the progress bar each time through the loop until reaching 100. In a real application though I want to start the progress bar when I select a file, then add progress to it until the entire process of retrieving data data from the file selected, build a sql query, executing the query and writing to a file completes. Since I'm not just adding to the bar each time through a loop I'm not sure how to go about doing this. Could anyone provide a real example?
Thanks
but this just adds to the progress bar each time through the loop until reaching 100. In a real application though I want to start the progress bar when I select a file, then add progress to it until the entire process of retrieving data data from the file selected, build a sql query, executing the query and writing to a file completes. Since I'm not just adding to the bar each time through a loop I'm not sure how to go about doing this. Could anyone provide a real example?
Thanks
Rich KPosted Apr 3, 2014, 2:43 PM
Munesh SharmaPosted Apr 3, 2014, 1:42 PM
Drag down a progress bar, a button and a timer. Now click on the button and write the code:
private void btnprogress_Click(object sender, EventArgs e)
{
this.timer1.start();
}
Now double click on timer
private void timer1_Click(object sender, EventArgs e)
{
this.btnprogress.increment(1);
}
We can also control the speed of the interval by a timer property.