A reference to the state object will be available in the events raised
by this method through the State property value. This is also valid
for the rest of asynchronous methods in MailBee.

Examples

Asynchronous connecting to a POP3 server in WinForms application. This sample
also handles Connected event. Wait method is used to wait
for the asynchronous method completion, since .NET's standard
WaitOne(Int32, Boolean) cannot process events.

// To use the code below, import MailBee namespaces at the top of your codeusing MailBee;
using MailBee.Pop3Mail;
// Put the code below inside your class// "Connected" event handlerprivatevoid OnConnected(object sender, ConnectedEventArgs e)
{
MessageBox.Show("Connected to the server");
}
// The actual codeprivatevoid Form1_Load(object sender, System.EventArgs e)
{
Pop3 pop = new Pop3();
// Let MailBee process events
pop.RaiseEventsViaMessageLoop = false;
pop.Connected += new ConnectedEventHandler(OnConnected);
// Initiate an asynchronous connection
pop.BeginConnect("pop.somehost.com", 110, true, null, null);
// Simulate some lengthy work here...for (int i = 0; i < 100; i++)
{
// Make a portion of the work
System.Threading.Thread.Sleep(10);
// Process events which were raised during execution of the work above
pop.Wait(0);
}
// If the connection was not established during execution of the lengthy // work, wait until it's established
pop.Wait();
// End the connection request
pop.EndConnect();
// Connected to the server!// Disconnect from the server
pop.Disconnect();
}

' To use the code below, import MailBee namespaces at the top of your codeImports MailBee
Imports MailBee.Pop3Mail
' Put the code below inside your class.' "Connected" event handlerPrivateSub OnConnected(ByVal sender As System.Object, ByVal e As ConnectedEventArgs)
MsgBox("Connected to the server")
EndSub' The actual codePrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As ConnectedEventArgs)
Dim pop AsNew Pop3
' Let MailBee process events
pop.RaiseEventsViaMessageLoop = FalseAddHandler pop.Connected, AddressOf OnConnected
' Initiate an asynchronous connection
pop.BeginConnect("pop.somehost.com", 110, True, Nothing, Nothing)
' Simulate some lengthy work here...Dim i AsIntegerFor i = 1To100' Make a portion of the work
System.Threading.Thread.Sleep(10)
' Process events which were raised during execution of the work above
pop.Wait(0)
Next' If the connection was not established during execution of the lengthy ' work, wait until it's established
pop.Wait()
' End the connection request
pop.EndConnect()
' Connected to the server!' Disconnect from the server
pop.Disconnect()
EndSub

Examples

Asynchronous connecting to a POP3 server in non-WinForms application.
Applications which do not have message loop (such as console or web applications)
can raise events on any thread and do not require any special events processing.