一段倒记时的代码,由于不停的执行,使CPU占用率永远100%。如何才能降下来呢?
代码如下:
Dim TotalSecond As Long
Dim RemainTime As Long
Dim BeforeSecond As Single
Dim k As Single
CancelDo = False
TotalSecond = 3600 * Hour(time1) + 60 * Minute(time1) + Second(time1)
BeforeSecond = Timer
Do While k <= TotalSecond
If CancelDo Then GoTo Quit
If Timer >= (BeforeSecond + k + 1) Then
RemainTime = TotalSecond - (k + 1)
Me.StatusBar1.Panels(2).Text = CStr(RemainTime \ 3600) & ":" & CStr((RemainTime Mod 3600) \ 60) _
& ":" & CStr((RemainTime Mod 3600) Mod 60)
k = k + 1
Else
DoEvents
End If
Loop
BeforeSecond = Timer
k = 0.25
Beep
Do While k <= 1
If Timer >= (BeforeSecond + k) Then Beep: k = k + 0.25
Loop
Quit:
.....
Exit Sub
能在不使用双线程的情况下解决这个东西吗?另外VB6.0是不是不支持双线程啊?
代码如下:
Dim TotalSecond As Long
Dim RemainTime As Long
Dim BeforeSecond As Single
Dim k As Single
CancelDo = False
TotalSecond = 3600 * Hour(time1) + 60 * Minute(time1) + Second(time1)
BeforeSecond = Timer
Do While k <= TotalSecond
If CancelDo Then GoTo Quit
If Timer >= (BeforeSecond + k + 1) Then
RemainTime = TotalSecond - (k + 1)
Me.StatusBar1.Panels(2).Text = CStr(RemainTime \ 3600) & ":" & CStr((RemainTime Mod 3600) \ 60) _
& ":" & CStr((RemainTime Mod 3600) Mod 60)
k = k + 1
Else
DoEvents
End If
Loop
BeforeSecond = Timer
k = 0.25
Beep
Do While k <= 1
If Timer >= (BeforeSecond + k) Then Beep: k = k + 0.25
Loop
Quit:
.....
Exit Sub
能在不使用双线程的情况下解决这个东西吗?另外VB6.0是不是不支持双线程啊?
do while
...
loop
中加入 DoEvents后。你再试试。
我看你还改改吧,哪有这么做倒计时的。Time = TimeSerial(Hours, Minutes, Seconds)
http://expert.csdn.net/Expert/topic/2011/2011010.xml?temp=.0315668
但最关键还是do while loop造成的CPU占用很高的问题~~
我在两个Do while .....loop中加了doevents ~好象还是这样~~~~大家还有什么办法吗??
请大家多发表一下看法吧