Asynchronous operations are useful because they occur without waiting for the action to complete before executing the next line of code. Such a technique is useful when an operation is time consuming and other code needs to execute without waiting for the operation to complete.
To get all messages asynchronously.
- Add the Pop component to a new form.
- Import the namespace of the component you would like to use using "Using" (C#) or "Imports" (VB.NET). Place the following code at the top of your file.
C#
Copy Codeusing Dart.PowerTCP.Mail;Visual Basic
Copy CodeImports Dart.PowerTCP.Mail - Add a button to the form.
- In this example, the Pop.BeginLogin method will be used. The Pop.EndLogin event will be raised when this operation has completed. "Wire-up" the Pop.EndLogin event.
- Set the properties required to properly get all messages from the server. Many of these properties default to the correct value required for getting all messages, but are still set to the proper value in the example below for emphasis. Place the following code in the Click event of the button added to the form in step 3.
C#
Copy Code// Be sure the Pop component is configured to automatically retrieve messages. pop1.AutoGet = MessageSection.Complete;Visual Basic
Copy Code' Be sure the Pop component is configured to automatically retrieve messages. Pop1.AutoGet = Complete - Use the BeginLogin method to automatically login to the server and all messages will be automatically retrieved. When this is complete, the EndLogin event will be raised. Place this code directly after the code from step 5.
C#
Copy Code// Login to the POP server. pop1.BeginLogin("mail.myserver.com", "test", "pass", null);
Visual Basic
Copy Code' Login to the POP server. Pop1.BeginLogin("mail.myserver.com", "test", "pass", Nothing)
- When the EndLogin event is raised, take some action (in this example, the number of attachments for each message are simply displayed). Your entire EndLogin event should look something like the following.
C#
Copy Codeprivate void pop1_EndLogin(object sender, System.EventArgs e) { // Iterate through the messages foreach(PopMessage msg in pop1.Messages) { // Display info about each Message Debug.Write("Message " + msg.Id); Debug.Write(" has " + msg.Attachments.Length + " attachments."); } }
Visual Basic
Copy CodePrivate Sub Pop1_EndLogin(ByVal sender As Object, ByVal e As System.EventArgs) Handles Pop1.EndLogin Dim Msg As PopMessage For Each Msg In Pop1.Messages ' Display info about each Message Debug.Write("Message " + Msg.Id) Debug.Write(" has " + Msg.Attachments.Length + " attachments.") Next End Sub