To prevent the user-interface from freezing, your application needs to call Application.DoEvents periodically while a time-consuming operation is in progress. The HeartbeatMs property is common to all Chilkat classes with events, and it controls the interval between AbortCheck callbacks. The AbortCheck callback provides (1) an opportunity for the application to call DoEvents, and (2) an opportunity for the application to abort the operation in progress.
This example demonstrates HeartbeatMs and AbortCheck in VB.NET for sending email:
Dim WithEvents m_mailman As Chilkat.MailMan
Dim m_abort As Boolean
' Call Application.DoEvents to keep the user-interface from "freezing".
Private Sub m_mailman_OnAbortCheck(ByVal sender As Object, ByVal args As Chilkat.AbortCheckEventArgs) Handles m_mailman.OnAbortCheck
Application.DoEvents()
' If the abort button was pressed, set the abort flag:
If (m_abort) Then
args.Abort = True
End If
End Sub
Private Sub m_mailman_OnSendPercentDone(ByVal sender As Object, ByVal args As Chilkat.MailPercentDoneEventArgs) Handles m_mailman.OnSendPercentDone
ProgressBar1.Value = args.PercentDone
' If the abort button was pressed, set the abort flag:
If (m_abort) Then
args.Abort = True
End If
End Sub
Private Sub btnAbort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbort.Click
m_abort = True
End Sub
Private Sub SendEmailWithProgress()
m_mailman = New Chilkat.MailMan()
Dim success As Boolean
success = m_mailman.UnlockComponent("Anything for 30-day trial")
If (Not success) Then
MessageBox.Show("Failed to unlock email component")
Exit Sub
End If
' Make sure to enable events:
m_mailman.EnableEvents = True
' Set the HeartbeatMs property so that AbortCheck events are periodically received
' every 100 milliSec:
m_mailman.HeartbeatMs = 100
m_mailman.SmtpHost = "mail.chilkatsoft.com"
m_mailman.SmtpUsername = "myLogin"
m_mailman.SmtpPassword = "myPassword"
Dim email As New Chilkat.Email()
email.Subject = "This is a test"
email.Body = "This is a test"
email.From = "support@chilkatsoft.com"
email.AddTo("Chilkat Admin", "admin@chilkatsoft.com")
' Before sending, give focus to our "Abort" button in the user interface.
' If focus is not given, it requires two clicks to abort -- the first
' click gives the button focus, the 2nd click first the "button click" event.
btnAbort.Focus()
m_abort = False
success = m_mailman.SendEmail(email)
MessageBox.Show(m_mailman.LastErrorText)
End Sub