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

February 11, 2008

Prevent VB.NET User-Interface from Freezing

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
        ' 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 = ""
        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 = ""
        email.AddTo("Chilkat Admin", "")
        ' 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.
        m_abort = False
        success = m_mailman.SendEmail(email)
    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.