1

I want to display progress bar when run a function. That progress bar value in change with run it.

I use background worker

private void worker_DoWork(object sender, DoWorkEventArgs e)
{
// run function.
}

While run function i want to change ProgressBar value.

I want to use ReportProgress(Int32) but what Int32 can i set for it?

ar.gorgin
  • 4,765
  • 12
  • 61
  • 100
  • possible duplicate of [Running a method in BackGroundWorker and Showing ProgressBar](http://stackoverflow.com/questions/13874122/running-a-method-in-backgroundworker-and-showing-progressbar) – Backs Aug 02 '15 at 08:23
  • Thanks, but in DoWork i serach,insert,delete item of DB. i don't have any loop for set value . – ar.gorgin Aug 02 '15 at 08:38
  • So, please add example of worker_DoWork method if you have no loops, it can be difficult to show progress in communication with db – Backs Aug 02 '15 at 08:54

1 Answers1

0

I guess if you have nothing to track progress of, the best you can do is to increment the progress bar after every line in the method, or have a different percentage complete after every line, depending on what the the line does:

public void Method()
        {
            Console.WriteLine("Hello");
            backgroundWorker1.ReportProgress(30);
            Console.WriteLine("World");
            backgroundWorker1.ReportProgress(60);
            //Do more work here....
            backgroundWorker1.ReportProgress(100);

        }


 private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
        }
Diza
  • 131
  • 2
  • 8