otherside Posted May 25, 2003 Posted May 25, 2003 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
*Gurus* divil Posted May 25, 2003 *Gurus* Posted May 25, 2003 Try the Sleep method of the Thread class. MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Leaders dynamic_sysop Posted May 25, 2003 Leaders Posted May 25, 2003 System.Threading.Thread.Sleep ' time in milliseconds '// eg: System.Threading.Thread.Sleep(10) just incase you havent used the Threading Sleep function before :)
otherside Posted May 25, 2003 Author Posted May 25, 2003 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 ?
Leaders dynamic_sysop Posted May 25, 2003 Leaders Posted May 25, 2003 maybe something like this. 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 )
maurad3r Posted May 30, 2003 Posted May 30, 2003 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: 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
thompsonson Posted June 25, 2003 Posted June 25, 2003 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
JizzLobber Posted July 8, 2003 Posted July 8, 2003 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.
Recommended Posts