你用那么多的代码 不如用这个PauseTime = 5   ' 设置暂停时间。
   Start = Timer   
   Do While Timer < Start + PauseTime
      DoEvents         
   Loop
msgbox "!"

解决方案 »

  1.   

    小呆,真的呆么?
    重复一下问题,一个Timer控件的Timer事件尚未退出时,下一个Timer事件能否进入。
    持否定态度的,发表观点有分(不要代码)
    持肯定态度(能重入)的,发表观点有分,给出能证明该观点的代码(必须能正确运行)100分
      

  2.   

    我觉得不会有重入的可能,一个Timer控件一定在一个线程中循环,怎么会重入呢?想要有重入现象,那必然是在进程中的多个线程中循环,我觉得不应该是多线程的。通过时钟所观察到的重入现象,只是Timer相对于系统时钟的延迟所造成的一种假象。
      

  3.   

    我没怎么用过timer控件,但我看了看书,我考虑应该可以的吧
      

  4.   

    我也认为不可以,但是有人给过一个类似的问题的解答,我未亲自证明(没有时间).现写出来.有人问:在commandA_onclick()未结束的时候,commandB_onclick()是否可以执行?
    我认为不可以,但是有人给出了一段代码.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的进程。不知哪位仁兄,可以把这段代码测试一下,然后把结果告诉大家.
      

  5.   

    Option Explicit
    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
    不可以的
    自己测试吧。
      

  6.   

    我想不可以吧,除非在TIMER事件中放入DOEVENTS
      

  7.   

    from MSDN:
    =================================
    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.
      

  8.   

    FROM MSDN:
    ============================================
    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. 
      

  9.   

    还有一点,楼主是否没有仔细看那文章===================
    这个问题虽然已经结贴,认为会重入的两位得分(我认为不会),即发贴者肯定了会重入(单没有例子)!
    ===================
    得分人-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事件的。
      
    =================================================================
    很明显看出,第二位得分居多的认为不能重入
      

  10.   

    不可以
    但在单片机(96)中的中断的是否重入是可以设置的。
    在windows中,中断是不会被相同级别的中断打断的。
    VB虽然是解释执行的程序但也一定尊寻windows这一原则。
    /*都是猜的*/
      

  11.   

    to  gump2000(阿甘)
    不是我没仔细看,而是你!
    Speedies(Speedies) 回答了两次,你贴出来的是第一次,第二次他改变了观点,认为可以重入(因此得分,呵呵!)
      

  12.   

    IsMe() :
    我以前遇到过这样的情况
    不知道怎么理解
    系统存在一个TIMER对连接与COM1上的IC读卡设备保持通讯
    而同时又存在一个TIMER对网络状态进行实时监控
    因为我一开始实现的时候对反应要求设置的比较高
    因此两个TIMER不能同时正常运行,最后我在实现中加上了足够的DOEVENTS得到了想要的效果。
    不过由于VB调试的时候是单线程的所以没有办法调试以确定
    不过我觉得可能不是TIMER本身决定的是否可以重入,而是在TIMER中所进行的操作是否可以并行的操作。
    可惜现在手上没有这样的环境不然可以再测试一下,要是不过我觉得可以试试在一个TIMER中对磁盘进行一个比较长时间的操作,而另一个进行网络请求等类似的操作,并加上了足够的DOEVENTS,看看是否可以得到合理的结果。
      

  13.   

    Private Sub Form_click() Timer1.Enabled = TrueEnd SubPrivate Sub Timer1_Timer() Static i As Long
     i = i + 1
     DoEvents
    Debug.Print "a" & i
    DoEvents
     For ii = 0 To 1000
      DoEvents
      Debug.Print ii
      DoEvents
     Next ii
    DoEvents
    End Sub答案是: 不行!!!!!
      

  14.   

    To: matrixshi(石头世界)
    你说的情况我认为应该有,但是,那其实是异步操作的,即在Timer事件中,调用了一个异步操作的命令(不用等待任务完成,即将控制返回),之后,顺利成章地退出了Timer事件,这时可能下一个Timer事件又触发,但虽然上次Timer事件已经退出,但是任务并没有完成,造成启动多个交错的任务。这种情况的实质是Timer事件没有重入,但调用的任务不会在一个进程,也不存在重入,但不同的任务可能会操作同样的数据区,造成任务执行错误。其实,我们在利用VB的ActiveX EXE执行异步操作时,也正是主动使用这样的技术:启动一个任务,处理该任务时,不是等处理完毕才退出过程,而是首先启动一个定时器,之后就退出过程,将控制返回调用者,在定时器到时间后,才真正启动任务。
      

  15.   

    我认为会重入!
    我想当 Time 事件触发时只是去处理 Time事件 中的代码!
    而定时器不会因为这段代码而停止工作!
    当下一次 Time 事件触发时还是 处理 Time 中的代码!
    它不会管你上一次执行完没有!
    除非你自己处理!