vb.net - How does the ProgressBar.PerformStep() function work? -


i'm quite confused progress bar in vb.net, here code

private sub form1_load(byval sender system.object, byval e system.eventargs) handles mybase.load     progressbar_my.minimum = 0     progressbar_my.maximum = 10     progressbar_my.step = 1 end sub  private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click      progressbar_my.performstep()     threading.thread.sleep(5000)     if 1 = 1         progressbar_my.performstep()         progressbar_my.performstep()     end if      'threading.thread.sleep(2000)  end sub 

for above code, expected after click button1, progress bar increase progress status 1, pause 5 sec, increase progress status 2 @ once.

however, after ran above code, saw after click button1, progress bar increase 3 continually after 5 sec.

can tell me why behaves , how should program code can increase 1, pause 5 sec , increase 2?

thanks in advance!

i think seeing (or not seeing) fact progress bar takes finite amount of time advance each step.

when call threading.thread.sleep on ui thread stops progress bar being redrawn until after sleep

what should update progress bar on background worker instead, think see effect desire.

add backgroundworker form

change button click code start worker:

private sub frmso_load(sender object, e eventargs) handles mybase.load     progressbar_my.minimum = 0     progressbar_my.maximum = 10     progressbar_my.step = 1 end sub  private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click     backgroundworker1.runworkerasync end sub 

then perform update in dowork event:

'define delegate handle updates ui thread private delegate sub performstepcallback()  private sub backgroundworker1_dowork(sender object, e system.componentmodel.doworkeventargs) handles backgroundworker1.dowork     dim cb performstepcallback = addressof progressbar_my.performstep     me.begininvoke(cb)     threading.thread.sleep(5000)     me.begininvoke(cb)     me.begininvoke(cb) end sub 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -