Pop3BeginConnect Method |
Note: This API is now obsolete.
Namespace: MailBee.Pop3Mail
[ObsoleteAttribute("This method is obsolete in .NET 4.5+. Use ConnectAsync instead.")] public IAsyncResult BeginConnect( string serverName, int port, bool pipelining, AsyncCallback callback, Object state )
Exception | Condition |
---|---|
MailBeeInvalidStateException | There is already an operation in progress. |
This method is an asynchronous version of Connect(String, Int32, Boolean).
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.
// To use the code below, import MailBee namespaces at the top of your code using MailBee; using MailBee.Pop3Mail; // Put the code below inside your class // "Connected" event handler private void OnConnected(object sender, ConnectedEventArgs e) { MessageBox.Show("Connected to the server"); } // The actual code private void 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(); }
using System; using MailBee; using MailBee.Pop3Mail; using MailBee.Mime; class Sample { // "Connected" event handler private static void OnConnected(object sender, ConnectedEventArgs e) { Console.WriteLine("Connected to the server"); } // The actual code static void Main(string[] args) { Pop3 pop = new Pop3(); pop.Connected += new ConnectedEventHandler(OnConnected); // Initiate an asynchronous connection pop.BeginConnect("pop.somehost.com", 110, true, null, null); // Simulate some lengthy work here... System.Threading.Thread.Sleep(1000); // If the connection was not established during execution of the lengthy work, // wait until it's established, and end the connection request pop.EndConnect(); // Connected to the server! // Disconnect from the server pop.Disconnect(); } }