Begins an asynchronous request for a logging in an account on a POP3 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 a mailbox and use of a callback function in a console application.
[C#] using System; using MailBee; using MailBee.Pop3Mail; class Sample { // A callback function. private static void LoginCallback(IAsyncResult result) { Pop3 pop = (Pop3)result.AsyncState; pop.EndLogin(); Console.WriteLine("Overall size of all messages in the inbox is " + pop.InboxSize + " bytes"); } // The actual code. static void Main(string[] args) { Pop3 pop = new Pop3(); pop.Connect("pop.somehost.com"); // Initiate an asynchronous login attempt. IAsyncResult ar = pop.BeginLogin("jdoe", "secret", AuthenticationMethods.Auto, AuthenticationOptions.None, null, new AsyncCallback(LoginCallback), pop); // 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 (pop.IsBusy) ar.AsyncWaitHandle.WaitOne(); // Disconnect from the server. pop.Disconnect(); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.Pop3Mail Class Sample ' A callback function. Private Shared Sub LoginCallback(ByVal result As IAsyncResult) Dim pop As New Pop3 pop = result.AsyncState pop.EndLogin() Console.WriteLine("Overall size of all messages in the inbox is " & _ pop.InboxSize & " bytes") End Sub ' The actual code. Shared Sub Main(ByVal args As String()) Dim pop As New Pop3 pop.Connect("pop.somehost.com") ' Initiate an asynchronous login attempt. Dim ar = pop.BeginLogin("jdoe", "secret", _ AuthenticationMethods.Auto, AuthenticationOptions.None, _ Nothing, New AsyncCallback(AddressOf LoginCallback), pop) ' 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 pop.IsBusy ar.AsyncWaitHandle.WaitOne() End While ' Disconnect from the server. pop.Disconnect() End Sub End Class
Pop3 Class | MailBee.Pop3Mail Namespace | Login | BeginConnect | SaslMethod