Application goes blanc

Hi when I'm using the graphics system to draw out points on my form in a loop ( finite) , the application sometimes goes blanc. It also doesn't update some labels even when these are in a different function.

Anyone had the same problem

I use this sub as a delay

Sub Delay()

Lvoltooid.Text = CStr((i / 100000) * 100) & "% is voltooid"

PgbVoltooid.Value = PgbVoltooid.Value + 1

System.Threading.Thread.Sleep(TBTijd.Value)

End Sub

 

But the Lvoltooid.Text just doesn't update



Answer this question

Application goes blanc

  • harrha19

    In the v2.0 version of the .Net framework there is a background worker class that you can use for lengthy operations where you periodically want to update the UI - documentation and a sample can be found at: http://msdn2.microsoft.com/library/System.ComponentModel.BackgroundWorker.aspx

    If you want to just create a "delay", I would recommend using a timer instead. On timer.Tick, do what you'd do up until the sleep and set the interval for the timer to the same value as you'd sleep... If the foreground thread sleeps, it will not paint your form.

    Best regards,
    Johan Stenberg



  • notoryus

    The article talks about C#

    I'm not familiar with that language at all. Is there one for VB. Net  Express Edition


  • Ferry Meidianto

    This certainly helps me how to solve the problem. It will take some time to get the point but thanks!
  • Carsten M. Horlacher

    I had this same type of problem where I was trying to update a label's text value.  I initially had the event take place right before loading a dataset with values (which performed some intense math and logic using vars dimed as double).  I played around with it, and ended up moving my label1.text= to a different place within my code in order to get it to work.  I even tried to issue a label1.update to force it to refresh, but still didn't work.

    I'd be interested to hear what others have experienced, or if a solution exists.

    Matt


  • dgrm44

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnforms/html/winforms06112002.asp explains what's happening and why.

    Best regards,
    Johan Stenberg

     



  • Application goes blanc