Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a way to specify the minimum and maximum value of progressbar while using it through backgroundprocess?

C#
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
     {

         int[] arr = new int[21];
         for (int i = 1; i <= 20; i++)
         {
             arr[i] = i;
             Thread.Sleep(100);
             int m = (int)((1* 100)/arr.Length);
             backgroundWorker1.ReportProgress(i*m);
         }
     }



I'm using the above code and it does not do the job.. The progress bar never reaches 100% as I'm just typecasting. I want to set the maximum value of progress bar to (arr.length) so that there's no need to typecast. Please help.
Posted
Updated 16-Oct-14 23:06pm
v2

 
Share this answer
 
Comments
Tejas Shastri 17-Oct-14 5:10am    
I have seen this.. Is it enough if I mention
<pre>progressbar1.Maximum = arr.Length;</pre>
in the backgroundprocess1_DoWork()?
MukeshSagar 17-Oct-14 5:53am    
no define at the page load event
Why are dealing that way with the array indices? I would have writeen it this way:
C#
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
     {
         int[] arr = new int[20];
         double d = 100.0 / arr.Length;
         for (int i = 0; i < arr.Length; i++)
         {
             arr[i] = (i+1);
             Thread.Sleep(100);
             int p = (int) Math.Round((i+1)* d);
             backgroundWorker1.ReportProgress(p);
         }
     }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900