Wait - Delay - Sleep in VB

Status
Not open for further replies.

otherside

Centurion
Joined
Mar 16, 2003
Messages
127
Location
UK - Greece
Hey guys does anyone know a way to make a delay in vb.net ?
is there any method that does that ?
i tried to do something with timer but unsuccesfully.
here is what i need

i have a sequence of functions which i need to run in specific time order
say:
function1
wait 5 seconds
function 2
wait 2 seconds
function 3
etc ..

i need something that will be stable not for example a for loop.

thanks guys, any example will be very helpfull
 
Visual Basic:
System.Threading.Thread.Sleep ' time in milliseconds
'// eg: System.Threading.Thread.Sleep(10)
just incase you havent used the Threading Sleep function before :)
 
guys thanks
normaly it works but i need to use it also within a loop and for some reason it doesn't work - the program halts and return results after it's out of the loop - , any other ideas ?
 
maybe something like this.
Visual Basic:
Dim f as Integer '// number of functions to use.
Dim i as Integer
For  i = 1 to f
'/// do the function
System.Threading.Thread.Sleep ' time to sleep
Next i
not tried it , but it seems logical ( and a similar principle works fine in vb6 )
 
otherside said:
guys thanks
normaly it works but i need to use it also within a loop and for some reason it doesn't work - the program halts and return results after it's out of the loop - , any other ideas ?
me too:
i use this code:
PHP:
Private Sub geefAntwoord_Click()
  antwoord.SetFocus
  status.Caption = "goede antwoord: " + antwoorden(current)
  Sleep 1000
  status.Caption = ""
End Sub
it has to work in this order:
1) status gets the caption "goede antwoord: "
2) wait 1 sec.
3) Clear the status

but what it does is:
1)wait a sec.
2) set status to "goede antwoorden" and clear it at once so you can't see it
 
Just the info I needed :)

maurad3r,
could what you are seeing be a result of windows not painting the status bar (or something along those lines). That's a poke in the dark for me, thought it may help...

Cheers,
Matt
 
Try adding a DoEvents

Try adding the .NET version of a DoEvents before the sleep statement:

Private Sub geefAntwoord_Click()
antwoord.SetFocus
status.Caption = "goede antwoord: " + antwoorden(current)
System.Windows.Forms.Application.DoEvents()
Sleep 1000
status.Caption = ""
End Sub

Cant be sure it will work but its worth a try.
 
Status
Not open for further replies.
Back
Top