Timer控件是不可重入?对象不可重入?类不可重入?
Timer控件.
同时存在两个timer控件,并且处理时间的超过interval的时候,就出现一些比较恶心的情况.
2个timer一个设置20,一个30,正常理解是2个timer处理完循环后,把自己的时间信息显示到自己对应的label,
但是实际情况变化了,只有一个label在更新,另外一个没有更新.
如果你的机器比较快,需要把循环时间调整更长一些,就是设置文本框里面的数字更大些.
我的问题是:是否timer是不可重入的?是否整个工程(或者是活动的这个窗体)里的多个timer也是限制重入,就是一个timer处理过程中
的时候,其他timer是阻塞的?
我的例子如下:
同时存在两个timer控件,并且处理时间的超过interval的时候,就出现一些比较恶心的情况.
2个timer一个设置20,一个30,正常理解是2个timer处理完循环后,把自己的时间信息显示到自己对应的label,
但是实际情况变化了,只有一个label在更新,另外一个没有更新.
如果你的机器比较快,需要把循环时间调整更长一些,就是设置文本框里面的数字更大些.
我的问题是:是否timer是不可重入的?是否整个工程(或者是活动的这个窗体)里的多个timer也是限制重入,就是一个timer处理过程中
的时候,其他timer是阻塞的?
我的例子如下:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2430
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 2430
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "Start"
Enabled = 0 'False
Height = 495
Left = 2880
TabIndex = 4
Top = 720
Width = 1575
End
Begin VB.CommandButton Command1
Caption = "Stop"
Height = 495
Left = 2880
TabIndex = 3
Top = 1320
Width = 1575
End
Begin VB.TextBox Text1
Height = 270
Left = 2040
TabIndex = 0
Text = "500"
Top = 240
Width = 975
End
Begin VB.Timer Timer2
Interval = 30
Left = 0
Top = 960
End
Begin VB.Timer Timer1
Interval = 20
Left = 0
Top = 1440
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "设置一个值,500-60000"
Height = 180
Left = 0
TabIndex = 5
Top = 240
Width = 1800
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "Label2"
Height = 180
Left = 480
TabIndex = 2
Top = 960
Width = 540
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Label1"
Height = 180
Left = 480
TabIndex = 1
Top = 1440
Width = 540
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim bStop As Boolean
Dim lCount As Long
Private Sub Command1_Click()
bStop = True
Timer1.Enabled = False
Timer2.Enabled = False
Command1.Enabled = False
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
bStop = False
Timer1.Enabled = True
Timer2.Enabled = True
Command1.Enabled = True
Command2.Enabled = False
End Sub
Private Sub Form_Load()
lCount = Val(Text1.Text)
End Sub
Private Sub Text1_Change()
If Not bStop Then
MsgBox "先停止那两个计时器"
Else
lCount = Val(Text1.Text)
End If
End Sub
Private Sub Timer1_Timer()
Dim i, j, k, l
k = Timer
For i = 1 To lCount
For j = 1 To lCount
l = j
If bStop Then Exit Sub
DoEvents
Next j
Next i
Label1.Caption = Timer & " " & Timer - k
End Sub
Private Sub Timer2_Timer()
Dim i, j, k, l
k = Timer
For i = 1 To lCount
For j = 1 To lCount
l = j
If bStop Then Exit Sub
DoEvents
Next j
Next i
Label2.Caption = Timer & " " & Timer - k
End Sub
...全文


VB基础类
