vb.net 睡眠函数 Visual Basic
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6191643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sleep function Visual Basic
提问by Jef Klak
Is there a simple sleep function in Visual Basic that doens't involve thread.
Visual Basic 中是否有一个不涉及线程的简单睡眠函数。
Something similiar like there exists in:
C: sleep(1);
类似的东西存在于: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 PInvoke 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.
检测到 PInvokeStackImbalance 消息:对 PInvoke 函数“Ganzenbordspel!Ganzenbordspel.Spel::Sleep”的调用使堆栈不平衡。这可能是因为托管 PInvoke 签名与非托管目标签名不匹配。检查 PInvoke 签名的调用约定和参数是否与目标非托管签名匹配。
回答by Helping
This one is much easie.
这个就简单多了。
Threading.Thread.Sleep(3000)
回答by Brad
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.)
由于您询问 .NET,您应该将参数从 更改Long
为Integer
。.NET 的整数是 32 位的。(经典 VB 的整数只有 16 位。)
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.
执行此操作时要小心。在表单应用程序中,您阻止了消息泵等等,使您的程序看起来像是挂了。很少是sleep
一个好主意。