你用那么多的代码 不如用这个PauseTime = 5 ' 设置暂停时间。
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
msgbox "!"
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
msgbox "!"
解决方案 »
- VB 中关于MSHFlexGrid1的背景颜色问题?
- 如何将imagelist中的对象加载到image 控件中?
- 是否能在程序中创建控件?
- 用ComboBox选择后,与数据库绑定的2个Text显示出与ComboBox.Text相应的记录。
- on err 的问题,为什么进入不了错误处理块
- VB如何使用一字节对其存储type?
- 在vb中如何在一个窗体中调用另个一个窗体,且把该窗体放在一个容器控件(如frame)中,
- 怎样在VB中用代码实现调用“数据链接属性”对话框,就是用ADODC生成“连接字符串时”调用的那个?
- 什么样的程序或功能,VB可以实现,VC不行?
- 如何自动换行?
- 怎样在vb中用字符串函数得到正确的字符子串
- 难题啊。关于模拟鼠标点击再98下不管用的问题。再线等待
重复一下问题,一个Timer控件的Timer事件尚未退出时,下一个Timer事件能否进入。
持否定态度的,发表观点有分(不要代码)
持肯定态度(能重入)的,发表观点有分,给出能证明该观点的代码(必须能正确运行)100分
我认为不可以,但是有人给出了一段代码.private m_blnBreak as booleanprivate sub command1_click()0D
...
doevents
if m_blnBreak then exit sub
end subprivate sub command2_click()0D
m_blnBreak=true
end sub
先按下command1,再按下command2,即可终止command1的进程。不知哪位仁兄,可以把这段代码测试一下,然后把结果告诉大家.
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Dim counti As IntegerPrivate Sub Form_Load()
Timer1.Interval = 1000
End SubPrivate Sub Timer1_Timer()
counti = counti + 1
Debug.Print "timer-" & counti
If counti = 5 Then Timer1.Enabled = False
Call test
End SubPrivate Sub test()
Debug.Print "test-" & counti & "(" & Now & ")"
Sleep 2000
End Sub
不可以的
自己测试吧。
=================================
If your application or another application is making heavy demands on the system — such as long loops, intensive calculations, or disk, network, or port access — your application might not get timer events as often as the Interval property specifies. Remember that the Timer event is periodic. The Interval property doesn't determine "how long" as much as it determines "how often." The length of the interval should depend on how much precision you want. Because there is some built-in potential for error, make the interval one-half the desired amount of precision.Note The more often a timer event is generated, the more processor time is consumed in responding to the event. This can slow down overall performance. Don't set a particularly small interval unless you need it.
============================================
Use static variables for information that must persist between occurrences of the Timer event procedure.
When the Timer event gets control, allow it to run slightly longer than the time you specified for the Interval property. This ensures that your background task will use every bit of processor time the system can give it. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The next Timer event will simply wait in the message queue until the last one is done.
=================================================================
Use a fairly large value — five to ten seconds — for the timer's Interval property, as this makes for more efficient processing. Preemptive multitasking prevents other applications from being blocked, and users are generally tolerant of a slight delay in canceling a long task.
Use the Enabled property of the Timer as a flag to prevent the background task from being initiated when it is already running.
这个问题虽然已经结贴,认为会重入的两位得分(我认为不会),即发贴者肯定了会重入(单没有例子)!
===================
得分人-1
=================================================================
回复人: rise139() ( ) 信誉:100 2002-5-25 14:36:39 得分:20
VB 是单线程的,你说的交叉问题不会发生,但如果你在getdata过程中放入DoEvents或类似的函数,交叉问题就会存在!得分人-2
=================================================================
回复人: Speedies(Speedies) ( ) 信誉:100 2002-5-30 21:58:57 得分:80
据我所知,Timer是不会出现交叉现象的。
不信把Timer的Interval 设置成1,然后再它的Timer事件中加上非常耗费CPU的算法,它不把这个算法摆平是不会再触发Timer事件的。
=================================================================
很明显看出,第二位得分居多的认为不能重入
但在单片机(96)中的中断的是否重入是可以设置的。
在windows中,中断是不会被相同级别的中断打断的。
VB虽然是解释执行的程序但也一定尊寻windows这一原则。
/*都是猜的*/
不是我没仔细看,而是你!
Speedies(Speedies) 回答了两次,你贴出来的是第一次,第二次他改变了观点,认为可以重入(因此得分,呵呵!)
我以前遇到过这样的情况
不知道怎么理解
系统存在一个TIMER对连接与COM1上的IC读卡设备保持通讯
而同时又存在一个TIMER对网络状态进行实时监控
因为我一开始实现的时候对反应要求设置的比较高
因此两个TIMER不能同时正常运行,最后我在实现中加上了足够的DOEVENTS得到了想要的效果。
不过由于VB调试的时候是单线程的所以没有办法调试以确定
不过我觉得可能不是TIMER本身决定的是否可以重入,而是在TIMER中所进行的操作是否可以并行的操作。
可惜现在手上没有这样的环境不然可以再测试一下,要是不过我觉得可以试试在一个TIMER中对磁盘进行一个比较长时间的操作,而另一个进行网络请求等类似的操作,并加上了足够的DOEVENTS,看看是否可以得到合理的结果。
i = i + 1
DoEvents
Debug.Print "a" & i
DoEvents
For ii = 0 To 1000
DoEvents
Debug.Print ii
DoEvents
Next ii
DoEvents
End Sub答案是: 不行!!!!!
你说的情况我认为应该有,但是,那其实是异步操作的,即在Timer事件中,调用了一个异步操作的命令(不用等待任务完成,即将控制返回),之后,顺利成章地退出了Timer事件,这时可能下一个Timer事件又触发,但虽然上次Timer事件已经退出,但是任务并没有完成,造成启动多个交错的任务。这种情况的实质是Timer事件没有重入,但调用的任务不会在一个进程,也不存在重入,但不同的任务可能会操作同样的数据区,造成任务执行错误。其实,我们在利用VB的ActiveX EXE执行异步操作时,也正是主动使用这样的技术:启动一个任务,处理该任务时,不是等处理完毕才退出过程,而是首先启动一个定时器,之后就退出过程,将控制返回调用者,在定时器到时间后,才真正启动任务。
我想当 Time 事件触发时只是去处理 Time事件 中的代码!
而定时器不会因为这段代码而停止工作!
当下一次 Time 事件触发时还是 处理 Time 中的代码!
它不会管你上一次执行完没有!
除非你自己处理!