devxlogo

Prevent Timer Re-Entry

Prevent Timer Re-Entry

When using a timer control, it is important to prevent re-entry.This occurs when the processing in the _Timer event takes long enough to still be executing when the next _Timer event fires. It is even possible for the execution of the second timer event to pass up that of the first. Depending on what the code does, re-entry can cause all sorts of hard-to-trace problems.
A simple solution is to disable the timer control during the timer event handler:

    Private Sub Timer1_Timer()      Timer1.Enabled = False      'rest of code goes here      Timer1.Enabled = True   End Sub

size=3>

devx-admin

Share the Post: