Begins an asynchronous request for a logging in an account on an IMAP4 server.
An IAsyncResult that references the asynchronous login process.
This method is an asynchronous version of Login.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidStateException | There is already an operation in progress. |
This sample demonstrates asynchronous logging in an account and use of a callback function in a console application.
[C#] using System; using MailBee; using MailBee.ImapMail; class Sample { // A callback function. private static void LoginCallback(IAsyncResult result) { Imap imp = (Imap)result.AsyncState; imp.EndLogin(); imp.SelectFolder("INBOX"); Console.WriteLine("Message #" + imp.Unseen + " is first unseen"); } // The actual code. static void Main(string[] args) { Imap imp = new Imap(); imp.Connect("imap.somehost.com"); // Initiate an asynchronous login attempt. IAsyncResult ar = imp.BeginLogin(null, null, "jdoe", "secret", AuthenticationMethods.Auto, AuthenticationOptions.None, null, new AsyncCallback(LoginCallback), imp); // Simulate some lengthy work here. At the same time, // login is executed on another thread. System.Threading.Thread.Sleep(3000); // If the login 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 Class Sample ' A callback function. Private Shared Sub LoginCallback(ByVal result As IAsyncResult) Dim imp As New Imap imp = result.AsyncState imp.EndLogin() imp.SelectFolder("INBOX") Console.WriteLine("Message #" & imp.Unseen & " is first unseen") End Sub ' The actual code. Shared Sub Main(ByVal args As String()) Dim imp As New Imap imp.Connect("imap.somehost.com") ' Initiate an asynchronous login attempt. Dim ar = imp.BeginLogin(Nothing, Nothing, "jdoe", "secret", _ AuthenticationMethods.Auto, AuthenticationOptions.None, _ Nothing, New AsyncCallback(AddressOf LoginCallback), imp) ' Simulate some lengthy work here. At the same time ' login is executed on another thread. System.Threading.Thread.Sleep(3000) ' If the login 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 Class
Imap Class | MailBee.ImapMail Namespace | Login | BeginConnect | SaslMethod