ImapBeginIdle Method |
Note: This API is now obsolete.
Namespace: MailBee.ImapMail
[ObsoleteAttribute("This method is obsolete in .NET 4.5+. Use IdleAsync instead.")] public IAsyncResult BeginIdle( AsyncCallback callback, Object state )
Exception | Condition |
---|---|
MailBeeInvalidStateException | There is already an operation in progress. |
// To use the code below, import MailBee namespaces at the top of your code using MailBee; using MailBee.ImapMail; // Put the code below inside your class. // Imap object declared global because it's accessed from several methods. Imap imp = null; bool started = false; // Monitor folder changes and save them in the log file. private void imp_MessageStatus(object sender, ImapMessageStatusEventArgs e) { ((Imap)sender).Log.WriteLine("Got " + e.StatusID + " status update"); } // Start/stop idling. // Add button1 on the form to make this sample working. private void button1_Click(object sender, System.EventArgs e) { if (started) { // Stop idling. imp.StopIdle(); imp.EndIdle(); // Disconnect from the server and revert to the original state. imp.Disconnect(); button1.Text = "Go idle"; started = false; } else { started = true; imp = new Imap(); // Enable logging into a file. imp.Log.Filename = @"C:\Temp\log.txt"; imp.Log.Enabled = true; imp.Log.Clear(); // Connect to the server and check if IDLE is supported. imp.Connect("mail.domain.com"); if (imp.GetExtension("IDLE") == null) { MessageBox.Show("IDLE not supported"); imp.Disconnect(); started = false; } else { // Login and select inbox. imp.Login("jdoe", "secret"); imp.SelectFolder("Inbox"); // Attach event handler. imp.MessageStatus +=new ImapMessageStatusEventHandler(imp_MessageStatus); button1.Text = "Stop idle"; // Go idle in the background. imp.BeginIdle(null, null); } } } // Finish idling if the user closes the application. // To make this method work, attach it to Closing event of the form. private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (imp != null && imp.IsBusy) { imp.StopIdle(); imp.EndIdle(); imp.Disconnect(); } }