3 Replies - 721 Views - Last Post: 30 August 2012 - 09:00 PM Rate Topic: -----

#1 Vladimir_Vaskev  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 31-August 11

Minimizing Render Delay (yeah, the description's my life story)

Posted 13 August 2012 - 10:39 PM

I recently decided to create a simple loop that increments i by one every time the loop runs. Whenever i

increments, it gets passed to a label. The idea was to display a rapidly incrementing number, unfortunately

when I run the loop, the program counts to the max amount for i, and then passes the final i value to the

label.
I then tried to do the same thing, but instead of sending it to the label, I added i to a listbox. The same

thing happended, but instead of only rendering the final value for i, it waited until the loop had

finished, then rendered every value for i.
I've asked around and apparently it has something to do with "threads"? Is there anywhere that has an

explanation for this?

More importantly though, how could I deal with the render delay for listboxes, or the problem with the

label? I have seen a solution that slows down the counting using a timer, but this seems like a work around

more than a solution. I understand that the label is recieving a new number to display before it has

finished rendering the last number, but surely there must be a way to speed up the rendering. I mean

slowing down the counting deliberately sounds counter-intuitive to me, let alone bad programming practice...

Anyway, here's the code I used for the label:

        Dim i As Integer
        i = 0
        While i < 100
            i += 1
            Label11.Text = i            
        End While



And here's the listbox:

        Dim i As Integer
        i = 0
        While i < 100
            i += 1
            ListBox2.Items.Add(i)            
        End While



Thanks for your help

Is This A Good Question/Topic? 0
  • +

Replies To: Minimizing Render Delay (yeah, the description's my life story)

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Minimizing Render Delay (yeah, the description's my life story)

Posted 13 August 2012 - 11:43 PM

You code looks like VB.Net code, not VB6.

That being said (assuming you have the same in VB.Net)....

The control has a REFRESH property, try calling it after each update.

You may also find that for such a small number to update, that if you really want to see it count up, you may need to add a delay on each iteration, dependent on the speed of the machine you're running it on.
Was This Post Helpful? 1
  • +
  • -

#3 Vladimir_Vaskev  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 31-August 11

Re: Minimizing Render Delay (yeah, the description's my life story)

Posted 14 August 2012 - 09:50 PM

Thankyou, I used:

        
    Dim i As Integer
        i = 0
        While i < 100
            i += 1
            CountLabel.Text = i
            CountLabel.Refresh()
        End While



For anyone looking for an explaination, here is what I THINK is happening:

From my understanding the label will not be repainted with the new value for i, until the loop is finished. However, by adding "CountLabel.Refresh()", we are forcing the program to repaint the label before i is incremented again. Although this would (I'm assuming) slow down the counting, the delay is not very noticable.
However, if you were to use the refresh function without specifying the object to repaint, eg. Refresh(), instead of CountLabel.Refresh(), you would repaint the entire form and all the objects within the form. So instead of refreshing a single object's image, you would refresh the image of every object in the form. Obviously this is A LOT slower and as such, you should always try to specify a single object to repaint.

This post has been edited by Vladimir_Vaskev: 14 August 2012 - 09:51 PM

Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Minimizing Render Delay (yeah, the description's my life story)

Posted 30 August 2012 - 09:00 PM

Good analysis. :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1