Begins an asynchronous request for closing (unselecting) the currently selected folder and optional removing of messages marked as deleted from this folder.
An IAsyncResult that references the asynchronous unselecting folder and expunging deleted messages process.
This method is an asynchronous version of Close.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidStateException | There is already an operation in progress. |
This WinForms sample demonstrates asynchronous unselecting the Inbox folder and expunging of all deleted messages if any.
[C#] // 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 imp = null; bool finished = false; // A callback function. Since it's called on Imap worker thread, // it cannot update controls on the form or otherwise access UI. // The only UI-related action permitted in worker thread is // displaying a message box (MessageBox.Show). // Any updates of UI must take place on message loop thread. // See BeginSearch method example on how to update UI in callbacks. private void CloseCallback(IAsyncResult result) { imp.EndClose(); finished = true; } // The actual code. private void Form1_Load(object sender, System.EventArgs e) { imp = new Imap(); // Connect to the server, login and select inbox. imp.Connect("mail.company.com"); imp.Login("jdoe@company.com", "secret"); imp.SelectFolder("Inbox"); // Start async close/expunge operation. imp.BeginClose(true, new AsyncCallback(CloseCallback), null); // Wait until it's finished. while (!finished) { // Process events on message loop thread. // Alternatively, we could set imp.RaiseEventsOnMessageLoop // to false and use imp.Wait method to perform waiting. System.Threading.Thread.Sleep(1); Application.DoEvents(); } // Close the connection. imp.Disconnect(); }
[Visual Basic] ' To use the code below, import MailBee namespaces at the top of your code. Imports MailBee Imports MailBee.ImapMail ' Put the code below inside your class. Dim imp As Imap = Nothing Dim finished As Boolean = False ' A callback function. Since it's called on Imap worker thread, ' it cannot update controls on the form or otherwise access UI. ' The only UI-related action permitted in worker thread is ' displaying a message box (MessageBox.Show). ' Any updates of UI must take place on message loop thread. ' See BeginSearch method example on how to update UI in callbacks. Private Sub CloseCallback(ByVal result As IAsyncResult) imp.EndClose() finished = True End Sub ' The actual code. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Dim imp As New Imap ' Connect to the server, login and select inbox. imp.Connect("imap.domain.com") imp.Login("jdoe", "secret") imp.SelectFolder("Inbox") ' Start async close/expunge operation. imp.BeginClose(True, New AsyncCallback(AddressOf CloseCallback), Nothing) ' Wait until it's finished. While Not finished ' Process events on message loop thread. ' Alternatively, we could set imp.RaiseEventsOnMessageLoop ' to false and use imp.Wait method to perform waiting. System.Threading.Thread.Sleep(1) Application.DoEvents() End While ' Close the connection. imp.Disconnect() End Sub
Imap Class | MailBee.ImapMail Namespace | Close