开发者

Sleep function Visual Basic

Is there a simple sleep function in Visual Basic that doens't involve thread.

Something similiar like there exists in: C: sleep(1);

We also tried this code:

Declare Sub Sleep Lib "kernel32" (ByVal milliseconds As Long)
' pause for 5 seconds
Sleep 5000

...but it didn't work. It gave me this error:

PInvokeStackImbalance was detected Message: A call to PI开发者_开发百科nvoke function 'Ganzenbordspel!Ganzenbordspel.Spel::Sleep' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.


This one is much easie.

Threading.Thread.Sleep(3000)


Since you are asking about .NET, you should change the parameter from Long to Integer. .NET's Integer is 32-bit. (Classic VB's integer was only 16-bit.)

Declare Sub Sleep Lib "kernel32.dll" (ByVal Milliseconds As Integer)

Really though, the managed method isn't difficult...

System.Threading.Thread.CurrentThread.Sleep(5000)

Be careful when you do this. In a forms application, you block the message pump and what not, making your program to appear to have hanged. Rarely is sleep a good idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜