Skip to content

Delay Component Overview

📖 Introduction

cDelay is a delay object class that supports three working modes: event-triggered mode, callback function mode, and synchronous wait mode. Suitable for various scenarios requiring delayed execution.

✨ Key Features

FeatureDescription
Three Working ModesEvent-triggered, callback function, synchronous wait
Parameter SupportCallback mode supports up to 9 parameters
UI ResponsiveSync mode uses message pump, does not block UI
CancellableSupports cancellation of delay operations
Global ManagementAutomatically manages global resources and instance counting

🚀 Quick Start

Event Mode (Default)

vb
Private WithEvents Delay As cDelay

Private Sub Form_Load()
    Set Delay = New cDelay
    Delay.CountDown 3000  ' Triggers OnTime event after 3 seconds
End Sub

Private Sub Delay_OnTime()
    Debug.Print "Delay ended!"
End Sub

Callback Mode

vb
Private Delay As cDelay

Private Sub TestCallback()
    Set Delay = New cDelay
    Delay.Callback(Me, "MyFunction", "param1", 123).CountDown 2000
End Sub

Public Sub MyFunction(ByVal p1 As String, ByVal p2 As Long)
    Debug.Print "Callback executed: " & p1 & ", " & p2
End Sub

Synchronous Wait Mode

vb
Private Delay As cDelay

Private Sub TestSync()
    Set Delay = New cDelay
    
    Debug.Print "Starting wait..."
    Delay.Sync().CountDown 3000  ' Wait 3 seconds, UI stays responsive
    
    If Delay.IsCancelled Then
        Debug.Print "Wait cancelled"
    Else
        Debug.Print "Wait completed"
    End If
End Sub

📋 Working Mode Comparison

ModeEnum ValueDescriptionUse Case
Event ModedmEventTriggers via OnTime eventUI operations requiring event response
Callback ModedmCallbackCalls specified method of specified objectScenarios requiring parameter passing
Sync ModedmSyncBlocks but processes messagesSequential execution while keeping UI responsive

Last Updated: 2026-05-17

VB6 and LOGO copyright of Microsoft Corporation