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: http://www.chilkatsoft.com/p/p_301.asp 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 = "mail.chilkatsoft.com"
mailman.PopUsername = "firstname.lastname@example.org"
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()
Private Sub AbortButton_Click()
bAbort = 1
' 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
Private Sub mailman_ReadPercentDone(ByVal percentDone As Long, abort As Long)
‘ Set abort = 1 if you wish to abort.
ProgressBar1.Value = percentDone
Private Sub Form_Load()
Set mailman = New ChilkatMailMan2
mailman.UnlockComponent "Anything for 30-day trial"
ProgressBar1.Value = 0
bAbort = 0