Begins an asynchronous request for copying or moving the specified messages from the currently selected folder to the specified folder.
An IAsyncResult that references the asynchronous copying or moving messages process.
This method is an asynchronous version of CopyMessages (if move is false) or MoveMessages (if move is true).
| Exception Type | Condition |
|---|---|
| MailBeeInvalidStateException | There is already an operation in progress. |
This console sample demonstrates asynchronous moving the first and the last messages from the Inbox folder into the Trash folder. A callback function is used as well.
The sample assumes "Trash" folder had already been created in the past. To learn how to make sure the folder exists, see UploadMessage or UploadMessage samples.
[C#] using System; using MailBee; using MailBee.ImapMail; class Sample { // A callback function. private static void CopyOrMoveMessagesCallback(IAsyncResult result) { Imap imp = (Imap)result.AsyncState; try { imp.EndCopyOrMoveMessages(); Console.WriteLine("The messages moved successfully"); } catch (MailBeeException e) { // In callback functions (generally speaking, in worker threads), // it's better to handle exceptions. If exception is not handled, // the worker thread silently dies and the application may never // know that something went wrong. Console.WriteLine(e.Message); } } // The actual code. static void Main(string[] args) { Imap imp = new Imap(); // Connect to the server, login and select inbox. imp.Connect("imap4.somehost.com"); imp.Login("jdoe", "secret"); imp.SelectFolder("INBOX"); // Initiate an asynchronous messages moving attempt. // We move the first and the last messages. IAsyncResult ar = imp.BeginCopyOrMoveMessages( "1," + imp.MessageCount.ToString(), false, "Trash", null, true, new AsyncCallback(CopyOrMoveMessagesCallback), imp); // Simulate some lengthy work here. At the same time, // messages are moved on another thread. System.Threading.Thread.Sleep(3000); // If the messages moving attempt is still in progress, // then wait until it's finished. while (imp.IsBusy) ar.AsyncWaitHandle.WaitOne(); // Disconnect from the server. imp.Disconnect(); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.ImapMail Module Sample ' A callback function. Private Sub CopyOrMoveMessagesCallback(ByVal result As IAsyncResult) Dim imp As Imap imp = CType(result.AsyncState, Imap) Try imp.EndCopyOrMoveMessages() Console.WriteLine("The messages moved successfully") Catch e As MailBeeException ' In callback functions (generally speaking, in worker threads), ' it's better to handle exceptions. If exception is not handled, ' the worker thread silently dies and the application may never ' know that something went wrong. Console.WriteLine(e.Message) End Try End Sub ' The actual code. Sub Main(ByVal args As String()) Dim imp As New Imap ' Connect to the server, login and select inbox. imp.Connect("imap4.somehost.com") imp.Login("jdoe", "secret") imp.SelectFolder("INBOX") ' Initiate an asynchronous messages moving attempt. ' We move the first and the last messages. Dim ar As IAsyncResult = imp.BeginCopyOrMoveMessages("1," & _ imp.MessageCount.ToString(), False, "Trash", Nothing, _ True, AddressOf CopyOrMoveMessagesCallback, imp) ' Simulate some lengthy work here. At the same time, ' messages are moved on another thread. System.Threading.Thread.Sleep(3000) ' If the messages moving attempt is still in progress, ' then wait until it's finished. While imp.IsBusy ar.AsyncWaitHandle.WaitOne() End While ' Disconnect from the server. imp.Disconnect() End Sub End Module
Imap Class | MailBee.ImapMail Namespace | CopyMessages | MoveMessages