C# Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C# Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

IMAP Progress Monitoring

Download Chilkat .NET for 4.0 Framework

Download Chilkat .NET for 64-bit 4.0 Framework (x64)

Download Chilkat .NET for 2.0 / 3.5 Framework

Download Chilkat .NET for 64-bit 2.0 / 3.5 Framework (x64)

Download Chilkat .NET for 1.0 / 1.1 Framework

IMAP progress monitoring in C#.

//  
private bool m_abortAtNextHeartbeat = false;

        private void btnGo_Click(object sender, EventArgs e)
        {
            // Any IMAP method call may be progress monitored and aborted.
            // This example demonstrates how to do it.
            Chilkat.Imap imap = new Chilkat.Imap();

            bool success;

            //  Anything unlocks the component and begins a fully-functional 30-day trial.
            success = imap.UnlockComponent("Anything for 30-day trial");
            if (success != true)
            {
                MessageBox.Show(imap.LastErrorText);
                return;
            }

            // IMPORTANT: To enable events, make sure the EnableEvents property is set to true.
            imap.EnableEvents = true;

            // This example describes two event callbacks: AbortCheck and PercentDone:
            imap.OnAbortCheck += new Chilkat.Imap.AbortCheckEventHandler(imap_OnAbortCheck);
            imap.OnPercentDone += new Chilkat.Imap.PercentDoneEventHandler(imap_OnPercentDone);

            // The AbortCheck event is fired periodically during any method call that communicates
            // with the IMAP server.  The rate of firing is controlled by the HeartbeatMs property.
            // If set to 0 (the default), then no AbortCheck events are fired.  Otherwise,
            // the HeartbeatMs property is the number of milliseconds between AbortCheck events.
            imap.HeartbeatMs = 100;     // Set it to 100 milliseconds.

            // NOTE: The PercentDone event is only fired for methods where it makes sense.
            // For example, the AbortCheck event is fired during a Connect method call,
            // but the PercentDone is not.  (It's not really possible to know the percentage
            // completion for a Connect -- the IMAP client simply waits for the server to accept
            // the connection.  However, when downloading 100 email headers, it's 50% done
            // when 50 email headers have been downloaded, and that makes sense.  When downloading
            // a single email that is 100K in size, it's 50% done when 50K has been downloaded,
            // again -- it makes sense.  If the PercentDone event does not fire -- ask yourself
            // if it even make sense.)

            // Now that events have been enabled, and event handlers are set,
            // the remainder of the code is identical to code that does not use events.
            // Skip down to review the OnPercentDone and OnAbortCheck events.

            // If you have an "Abort" button in your user-interface, you may wish
            // to give it focus prior to calling progress-monitored methods:
            btnAbort.Focus();

            //  Connect to an IMAP server.
            success = imap.Connect("mail.chilkatsoft.com");
            if (success != true)
            {
                MessageBox.Show(imap.LastErrorText);
                return;
            }

            //  Login
            success = imap.Login("myLogin", "myPassword");
            if (success != true)
            {
                MessageBox.Show(imap.LastErrorText);
                return;
            }

            //  Select an IMAP mailbox
            success = imap.SelectMailbox("Inbox");
            if (success != true)
            {
                MessageBox.Show(imap.LastErrorText);
                return;
            }

            Chilkat.MessageSet messageSet = null;
            //  We can choose to fetch UIDs or sequence numbers.
            bool fetchUids;
            fetchUids = true;
            //  Get the message IDs of all the emails in the mailbox
            messageSet = imap.Search("ALL", fetchUids);
            if (messageSet == null)
            {
                MessageBox.Show(imap.LastErrorText);
                return;
            }

            // In this example, FetchBundle is the only method that
            // will fire PercentDone events.

            //  Fetch the emails into a bundle object:
            Chilkat.EmailBundle bundle = null;
            bundle = imap.FetchBundle(messageSet);
            if (bundle == null)
            {

                MessageBox.Show(imap.LastErrorText);
                return;
            }

            //  Loop over the bundle and display the FROM and SUBJECT of each.
            int i;
            for (i = 0; i <= bundle.MessageCount - 1; i++)
            {
                Chilkat.Email email = null;
                email = bundle.GetEmail(i);
                textBox1.Text += email.From + "\r\n";
                textBox1.Text += email.Subject + "\r\n";
                textBox1.Text += "--" + "\r\n";

            }

            //  Disconnect from the IMAP server.
            imap.Disconnect();

        }

        void imap_OnPercentDone(object sender, Chilkat.PercentDoneEventArgs args)
        {
            // Update the progress bar.
            // args.PercentDone is an integer value that has a value from 0 to 100.
            progressBar1.Value = args.PercentDone;
        }

        // This is called periodically according to the HeartbeatMs
        void imap_OnAbortCheck(object sender, Chilkat.AbortCheckEventArgs args)
        {
            // To abort any Chilkat IMAP method call, simply set the  
            // args.Abort property to true:
            if (m_abortAtNextHeartbeat)
            {
                args.Abort = true;
                m_abortAtNextHeartbeat = false;
            }

            // Keep the user-interface responsive by allowing UI events to be processed:
            Application.DoEvents();
        }

        private void btnAbort_Click(object sender, EventArgs e)
        {
            m_abortAtNextHeartbeat = true;
        }

 

© 2000-2012 Chilkat Software, Inc. All Rights Reserved.

Email Component · XML Parser