sleep?

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.
 
Z

zacks

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.
 
H

Herfried K. Wagner [MVP]

guy said:
System.Threading.Thread.CurrentThread.Sleep( )

Better simply call 'System.Threading.Thread.Sleep', which will block
execution of the thread calling the method.
 
C

CMM

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.
 
M

m.posseth

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]
 
C

CMM

VB6?

The .NET answer had already been posted. I was asking about the OT
mentioning VB6.
 
M

m.posseth

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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top