睡眠功能不起作用。宣言?

时间:2014-11-30 12:25:33

标签: vb.net

我有这段代码:

My.Computer.FileSystem.RenameFile("C:\Users\mario\Desktop\Dominio\1\Pc - S.txt", "Pc - S - A.txt")
Sleep(2000)
My.Computer.FileSystem.RenameFile("C:\Users\mario\Desktop\Dominio\1\Pc - S - A.txt", "Pc - S.txt")

但是当我运行它时,会出现以下错误消息:

Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in 'C:\Users\mario\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.vshost.exe'.
Additional Information: A call to PInvoke function 'WindowsApplication1!WindowsApplication1.Form1::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.

什么是hapening?我用它来声明它:Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

什么是hapening,我该如何解决?我认为是宣言..

解决方案:只需使用它:System.Threading.Thread.Sleep(2000)             它不使用声明。

2 个答案:

答案 0 :(得分:3)

你的声明是错误的,Sleep()参数是Integer,而不是Long。注意你在各种网页中找到的旧VB6声明,几乎任何使用Long的东西都是错误的VB.NET。 VB6类型基于其16位版本,VB4是最后一个版本。

请勿执行此操作,而是使用.NET method

答案 1 :(得分:2)

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

您应该特别注意类型声明。 Longs比以前在VB6中更大,因此您需要确保您从Web上获得的任何代码都适合您当前的环境。