sleep?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm new to VB.Net. Wondering how you do a sleep for x milliseconds and then
continue executing on the next line? This was done in VB6 and wondering how
it's done in VB.Net.
 
System.Threading

Imports System.Threading

public sub mySub

'do something before waiting
Thread.Sleep(2000) ' sleeps for 2000 milliseconds
'do something after waiting

end sub

Can get you in trouble if you have multiple threads unless you are
careful.
 
guy said:
System.Threading.Thread.CurrentThread.Sleep( )

Better simply call 'System.Threading.Thread.Sleep', which will block
execution of the thread calling the method.
 
I don't remember this being available in VB6?!
I know you could do it using the Win32 Sleep API... but it wasn't part of
VB6.
 
Imports System

Public Module modmain

Sub Main()

Console.WriteLine("I wait five seconds")

System.Threading.Thread.Sleep(5000)

Console.WriteLine("five seconds have passed")

End Sub

End Module





regards



Michel Posseth [MCP]
 
well in my newsgroup reader the .Net answer wasn`t showed i see now that
this was on a seperate thread


about the vb6 thingy

afaik this can only be done like this

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Command1_Click()



Me.Caption = "Your system will sleep 5 sec."

'Sleep for 5000 milliseconds

Sleep 5000

Me.Caption = ""

End Sub

Private Sub Form_Load()

Me.Caption = ""

Command1.Caption = "Sleep ..."

End Sub

regards

Michel Posseth [MCP]
 
Back
Top