iamwoturnot
New member
- Joined
- Aug 12, 2010
- Messages
- 3
- Programming Experience
- 5-10
Is it possible to time the interval between items in a listbox in a for loop? I have a for loop to loop through items in a listbox, and I want to set a timed interval between each item in the loop and run a command after each one, but when I try to do this with a timer, the set interval ticks off and then the loop is executed really fast. The only thing I have gotten to work is using sleep, which works between each item, but that freezes the form and that isn't what I want.
I want a set interval between each item within the loop. How do I do this if it is possible? Here is my loop currently using the sleep function. I don't have any examples of my attempts to use the timer because after several tries, I have given up and this what I currently have written:
This is the only thing I have gotten to work where there is a 5 second interval between each item and my command runs, but the form is unresponsive during the loop. I know this isn't the correct approach, but I have not been able to make it do like I want with the timer. Should I be using a For Each instead? Any help or advise would be greatly appreciated. Thanks in advance.
I want a set interval between each item within the loop. How do I do this if it is possible? Here is my loop currently using the sleep function. I don't have any examples of my attempts to use the timer because after several tries, I have given up and this what I currently have written:
VB.NET:
For i As Integer = 0 To FormMain.ListBox1.Items.Count - 1
listitem = CStr(FormMain.ListBox1.Items(i))
System.Threading.Thread.Sleep(5000)
execute code for item here with a sub using listitem variable
Next i
This is the only thing I have gotten to work where there is a 5 second interval between each item and my command runs, but the form is unresponsive during the loop. I know this isn't the correct approach, but I have not been able to make it do like I want with the timer. Should I be using a For Each instead? Any help or advise would be greatly appreciated. Thanks in advance.
Last edited: