Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delay with loop
Hello it's me again. Now i am trying to make delay with loop. If i am using:
The program freezes until loop stops. Can i make somehow that program won't freeze when the loop is not finished? Thanks in advance Smile
Yes, you can use an onbect called backgroundworker:
1)Find the backgroundworker from the toolbox and add it to your form
2)Doubleclick the object added
3)In the event that appears add your code(the loop you want)
4)Now when you want to run this loop just use:
BackgroundWorker1.RunAsynchronousOperation() 'or something similar to it I don't remember it exactly
What did you just do with these actions? You now run the loop in a different thread. So when you use Threading.Thread.Sleep(500) only the thread of the loop freezes and not the entire application. However, notice there is one limitation: you can't edit any object in the form from a different thread. This means that a code like Textbox1.Text="Hello World" would cause a runtime error if it is used from within the BackgroundWorker.

Edit: You can also make your own threads without using the BackgoundWorker, which is much better, but a little more difficult for beginners. If you want to learn about it however, google VB.NET threading
My software company: Porosis Software
Games: Terrantula
Apps: Mathanasis, ColorGrabber

Possibly Related Threads...
Thread Author Replies Views Last Post
  [VB.Net] Time Delay While Keeping UI Functional (Delegates, StopWatch, Threads) AceInfinity 0 719 09-03-2012, 11:19 PM
Last Post: AceInfinity
  Loop through textbox KoBE 0 556 11-17-2010, 03:53 AM
Last Post: KoBE

Forum Jump:

Users browsing this thread: 1 Guest(s)