AddinTimer class

A simple periodic-callback helper. AddinTimer is the only user-instantiable class in the package — every other CoClass is handed to the addin by the IDE; this one the addin creates with New. Internally it wraps the Win32 SetTimer / KillTimer pair against hwnd = 0 and fires its Timer event from the IDE’s UI thread.

Private WithEvents Timer As AddinTimer

Private Sub Button1_OnClick()
    Set Timer = New AddinTimer
    Timer.Interval = 500          ' milliseconds
    Timer.Enabled  = True
End Sub

Private Sub Timer_Timer()
    ' fires every 500 ms on the IDE's UI thread
End Sub

Stop the timer by setting Enabled = False, or simply by dropping the last reference — Class_Terminate cancels the underlying Win32 timer automatically. Both Enabled and Interval are live: assigning to either re-arms the underlying Win32 timer using the new values, so changing the interval while the timer is running takes effect immediately.

Nothing in the package requires this helper — a direct SetTimer / KillTimer pair (or any other periodic mechanism) works just as well; sample 15’s dwell-time pattern uses raw Win32 calls. Use AddinTimer when the convenience of an event-bound class is preferable to managing the Win32 plumbing yourself.

Properties

Enabled

Controls whether the underlying Win32 timer is running. Boolean, default False. Assigning to Enabled re-arms (or cancels) the timer immediately.

Syntax: timer.Enabled [ = value ]

Interval

The timer’s period, in milliseconds. Long, default 0. With Interval = 0 the timer is effectively inert; set a positive value and Enabled = True to start the periodic callback. Assigning to Interval re-arms the timer with the new value, so the next tick fires after the new interval rather than the old one.

Syntax: timer.Interval [ = milliseconds ]

Events

Timer

Fires every Interval milliseconds while Enabled is True. Runs on the IDE’s UI thread.

Syntax: timer_Timer()

Long-running work inside the handler will block the UI thread until it returns — keep the handler short and offload heavy work to a background mechanism if needed.