Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

November 9, 2007

Progress Monitoring in VB6 without Freezing the User Interface

This blog post describes how to use events to monitor the progress (with abort capability) of a Chilkat method call, while keeping the user-interface responsive.

One note: This article shows how to do it in the foreground thread. Passing events from background to foreground threads could be a tricky matter. This article discusses how to do it in VB.NET: I suspect that it’s not directly possible to update a Form control in VB6 from a background thread.

Ok, let’s begin…

The Chilkat components (Email, IMAP, HTTP, FTP2, Zip, etc.) provide a common property named HeartbeatMs. This controls the frequency, in milliseconds, at which an AbortCheck event is fired during a lengthy non-blocking call — such as when reading email, downloading a file, creating a zip archive, etc. The default value of HeartbeatMs is 0, which means that AbortCheck events are not called.

The trick to keeping your VB6 user-interface responsive is to set HeartbeatMs to a small value, such as 100ms. Within the AbortCheck event, call DoEvents to allow the VB6 runtime to process UI events. Here’s an example:

' When using events, you must declare the mailman "withevents"
Public WithEvents mailman As ChilkatMailMan2
Dim bAbort As Integer
Private Sub ReadEmail_Click()
    mailman.MailHost = ""
    mailman.PopUsername = ""
    mailman.PopPassword = "****"
    mailman.HeartbeatMs = 100
    Dim bundle As ChilkatEmailBundle2
    ' Copy the email from the POP3 server without removing it.
    ' The progress bar will update with the percentage completion as
    ' the CopyMail proceeds.
    Set bundle = mailman.CopyMail()
    ' ...
End Sub
Private Sub AbortButton_Click()
    bAbort = 1
End Sub
' Abort check is called at intervals according to HeartbeatMs
Private Sub mailman_AbortCheck(abort As Long)
    ‘ If the abort button was pressed, bAbort is 1 and
    ‘ the operation is aborted.
    abort = bAbort
End Sub
Private Sub mailman_ReadPercentDone(ByVal percentDone As Long, abort As Long)
    ‘ Set abort = 1 if you wish to abort.
    ProgressBar1.Value = percentDone
End Sub
Private Sub Form_Load()
    Set mailman = New ChilkatMailMan2
    mailman.UnlockComponent "Anything for 30-day trial"
    ProgressBar1.Value = 0
    bAbort = 0
End Sub

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.