I've been struggling with ProgressBars, loops, threads and timers for a while.
Some times with success some times not. So I decided to start with super basic examples.
I've created a new desktop application. One window with one Progressbar (named "pb") and a Label (named "lb").
On the Activate event of the main window I've created this code:
Self.show Dim t As Integer = Ticks pb.value = 0 pb.Maximum = 10000 For i As Integer = 1 To 10000000 If i Mod 1000 = 0 Then ' pb.Value = i/1000 'lb.Text = Str(i/1000) End If Next i MsgBox str(ticks - t)
It is a 10 million loop. At the end I get a message of 57 ticks. As far as good.
If I uncomment
lb.Text = Str(i/1000) it takes 80 ticks but I see only the last value for the label.
It is OK because I understand that the UI is not updated during a loop.
But if I uncomment
pb.Value = i/1000 the ProgressBars fills smoothly, and at the end it is completely full. It takes 73 ticks.
My question is:
If a ProgressBar is a control, why does it get updated in the loop? Wasn't it necessary to use threads and timers?
Thanks for your clarifying it.