用API函数 sleep: Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub Command1_Click() Sleep 10000 '延时10000毫秒,即10秒 MsgBox "End of Sleep!" End Sub
可惜vb里没有vc的一个函数SwitchToThread,他的效率比sleep要高 那你试试WaitForSingleObject函数 Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
WaitForSingleObject ?cso,能不能给个例子说明如何用?
这样是不是会好一点: DO UNTIL ..... DOEVENTS SLEEP 50 LOOP 这样程序就不会象死了一样,而CPU也不会占100%了
Public Sub yanshi(time As Integer) '延时函数 Dim Savetime As Double Savetime = timeGetTime '记下开始时的时间 While timeGetTime < Savetime + time '循环等待 DoEvents '转让控制权,以便让操作系统处理其它的事件。 Wend End Sub
Declare Function timeGetTime Lib "winmm.dll" () As Long '得到开机以来的毫秒数 Public Sub yanshi(time As Integer) '延时函数 Dim Savetime As Double Savetime = timeGetTime '记下开始时的时间 While timeGetTime < Savetime + time '循环等待 DoEvents '转让控制权,以便让操作系统处理其它的事件。 Wend End Sub
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub Command1_Click()
Sleep 10000 '延时10000毫秒,即10秒
MsgBox "End of Sleep!"
End Sub
那你试试WaitForSingleObject函数
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
DO UNTIL .....
DOEVENTS
SLEEP 50
LOOP
这样程序就不会象死了一样,而CPU也不会占100%了
Dim Savetime As Double
Savetime = timeGetTime '记下开始时的时间
While timeGetTime < Savetime + time '循环等待
DoEvents '转让控制权,以便让操作系统处理其它的事件。
Wend
End Sub
Public Sub yanshi(time As Integer) '延时函数
Dim Savetime As Double
Savetime = timeGetTime '记下开始时的时间
While timeGetTime < Savetime + time '循环等待
DoEvents '转让控制权,以便让操作系统处理其它的事件。
Wend
End Sub