ImapBeginCopyOrMoveMessages Method |
Note: This API is now obsolete.
Namespace: MailBee.ImapMail
[ObsoleteAttribute("This method is obsolete in .NET 4.5+. Use CopyMessagesAsync or MoveMessagesAsync instead.")] public IAsyncResult BeginCopyOrMoveMessages( string messageIndexSet, bool indexIsUid, string targetFolderName, UidPlusResult result, bool move, AsyncCallback callback, Object state )
Exception | 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(MailMessage, String, String, DateTime) or UploadMessage(MailMessage, String, String, String) samples.
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(); } }