Itβs true that you cannot know exactly how many iterations your loops will perform, but you will probably be able to smooth out the progress indicator.
Suppose your worst case iterations are xMax * yMax * mostZMax.
mostZMax = 99 because the upper bound is exclusive in Random.Next(minValue:int, maxValue:int)
Therefore, the final iterations in the worst case will be 5 * 10 * 99 = 4950 .
Now we could start with this amount and adjust it if necessary, when we lose iterations after generating zMax for each cycle y, and we will smooth out progress and reporting efficiently.
Here's how I do it:
private void bgw_DoWork(object sender, DoWorkEventArgs e) { const int xMax = 10; const int yMax = 5; const int worstZMax = 99;
Hope this helps!
source share