Sleep或强制循环+DOEVENTS都占CPU100%,有其他的办法吗?谢谢!
解决方案 »
- vb下能不能写AUTOEXEC.BAT文件?
- 欢迎vb新手高手加入QQ群15763579 大家一起进步
- 如何用VB强制杀死EXCEL进程?
- 如何使datagrid控件在显示数据时自动选择列宽?
- 控件ctlbar32.ocx该控件在编译生成可执行文件的时候显示不出来
- 怎样象winrar一样创建一个鼠标快捷按扭,在任意程序中点右键均能弹出我设定的命令按扭
- 关于设置更改密码的问题
- 如果找出Crystl Report里面与显示报表有关的文件,急!!!!!!!!!
- 如何将同一个程序分配给不同的进程
- VB 关于 ipad 横竖屏幕切换
- [分享]一个不错的控件 lchAutoSize (VB6.0自动调整窗口布局控件)
- 怎样实现类似dos中debug的-o 2a8 ff命令?
在机能充许的情况下,精度应该是0。05秒。
使用时只要加类似Delay(1.05)即可,Option Explicit
Public Declare Function GetTickCount Lib "kernel32" () As Long
Const MS_DELAY = 50 '20FPSPublic Function Delay(Times As Single)
Dim mblnRunning As Boolean
Dim mlngTimer As Long
Dim caculate As Single
mblnRunning = True
caculate = 0
Debug.Print Times
Do While mblnRunning And caculate < Times
If mlngTimer + MS_DELAY <= GetTickCount() Then
mlngTimer = GetTickCount()
caculate = caculate + 0.05
End If
DoEvents 'Important!
Loop
End Function
Public Function pause(seconds As Integer)
Const SECS_INDAY = 24! * 60 * 60
Dim start As Single
start = Timer
Do: Loop Until (Timer + SECS_INDAY - start) Mod SECS_INDAY >= seconds
End Function
Sleep 1 ' to prevent hogging of the CPU
Dim tm1, tm2 As Single
tm1 = Timer
Do
tm2 = Timer
If tm2 < tm1 Then tm2 = tm2 + 86400
If tm2 - tm1 > n Then Exit Do
DoEvents
Loop
End Function
sleep 1
doevents
是不会占CPU资源的,如果你的CPU占用率还是100%,那么肯定是别的地方造成的。
在你要暂停的地方弹出模式窗体,styleboder设为1,并设为一象素大小,上面放一timer,就搞了,
时间到了,就unload
如果你发现sleep占cpu,那么是你其他地方占了CPU
这样的话,如果你用其他方法暂停,也是要占cpu的
占cpu的地方可能是你doevents的地方造成的
你检查其他地方把,光延迟 sleep或者getTickCount都可以的