How do i calculate in the background1 DoWork event so the ReportProgress(percentage) will get to 100

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Thats what i did in the DoWork event and in the ProgressChanged event:


<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; private <span style="color:Blue; void backgroundWorker1_DoWork(<span style="color:Blue; object sender, DoWorkEventArgs e)
{
<span style="color:Blue; double total = streamlength;
<span style="color:Blue; int counter = 0;
<span style="color:Blue; int percentage = 0;
BackgroundWorker bgw = (BackgroundWorker)sender;
<span style="color:Blue; int i = 0;

<span style="color:Blue; for (<span style="color:Blue; double x = 0; x < streamlength; x += dt)
{

streamDouble[0] = x;
SaveFramesFromVideo(strVideoFile, streamDouble, sf + i.ToString(<span style="color:#A31515; "D6") + <span style="color:#A31515; ".bmp");
i++;
counter += 1;
percentage = counter * 100 / (<span style="color:Blue; int)total;
bgw.ReportProgress(percentage);
}
}

<span style="color:Blue; private <span style="color:Blue; void backgroundWorker1_ProgressChanged(<span style="color:Blue; object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
[/code]

I see the progressBar1 progress with the green color from left to right but in the middle im getting exception in the ProgressChanged event:

ArgumentOutOfRangeException: Value of 133 is not valid for Value. Value should be between minimum and maximum.<br/>
Parameter name: Value

The error is on the line: progressBar1.Value = e.ProgressPercentage; in the progressChanged event. <hr class="sig danieli

View the full article
 
Back
Top