PowerTCP Mail for .NET
Displaying POP Progress
Send comments on this topic.



Glossary Item Box

It is often desirable, when your applications perform actions that could take longer than a few seconds, to display the progress of the action to the user. The Pop component fully supports progress notification through the Progress event. The Progress event will be raised periodically while data transfer is in progress, making accessible necessary data to display progress information, such as the size of the message and the current position within the message.

To display progress when getting messages.

  1. Add the Pop component to a new form.
  2. 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 Code
    using Dart.PowerTCP.Mail;
    Visual Basic Copy Code
    Imports Dart.PowerTCP.Mail
  3. Add a button to the form.
  4. Call a method that could conceivably take a while to complete, (ex: getting many messages from a mailbox or getting a message containing a large attachment from a mailbox). 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;
    
    // Login to the POP server and get all messages.
    pop1.Login("mail.myserver.com", "test", "pass");
    Visual Basic Copy Code
    ' Be sure the Pop component is configured to automatically retrieve messages.
    Pop1.AutoGet = MessageSection.Complete
    
    ' Login to the POP server and get all messages.
    Pop1.Login("mail.myserver.com", "test", "pass")
  5. The Pop.Progress event will be raised whenever progress information is available. "Wire-up" the Pop.Progress event.
  6. Add two ProgressBar objects and one Label object.
  7. In this example, several types of progress information will be demonstrated. One ProgressBar object will provide progress information for ALL messages being retrieved. The other ProgressBar object will provide progress information for EACH message being retrieved. The label will be used to display textual progress info.  Add the following code to your Progress event handler. When finished, your Progress event handler should look similar to the following.
    C# Copy Code
    private void pop1_Progress(object sender, Dart.PowerTCP.Mail.PopProgressEventArgs e)
    {
       // Set up progressBar1. This will display progress for all messages received.
       progressBar1.Minimum = 0;
    
       // Use the total number of all messages being retrieved for Length
       progressBar1.Maximum = (int)pop1.Messages.Length;
    
       // Use the numerical ID (which are in the range [1 - number of messages] 
       // as the value.
       progressBar1.Value = System.Convert.ToInt32(e.PopMessage.Id);
    
       // Set up progressBar2. This will display progress for each message received.
       progressBar2.Minimum = 0;
    
       // Length represents the Length of the data for the current message being processed.
       progressBar2.Maximum = (int)e.Length;
    
       // Position represents the current Position in the stream of the message being processed.
       progressBar2.Value = (int)e.Position;
    
       // Display a message as well.
       label1.Text = "Processing message " + e.PopMessage.Id;
    }
    Visual Basic Copy Code
    Private Sub Pop1_Progress(ByVal sender As Object, ByVal e As Dart.PowerTCP.Mail.PopProgressEventArgs) Handles Pop1.Progress
    
       ' Set up progressBar1. This will display progress for all messages received.
       ProgressBar1.Minimum = 0
    
       ' Use the total number of all messages being retrieved for Length
       ProgressBar1.Maximum = Pop1.Messages.Length
    
       ' Use the numerical ID (which are in the range [1 - number of messages]
       ' as the value.
       ProgressBar1.Value = System.Convert.ToInt32(e.PopMessage.Id)
    
       ' Set up progressBar2. This will display progress for each message received.
       ProgressBar2.Minimum = 0
    
       ' Length represents the Length of the data for the current message being processed.
       ProgressBar2.Maximum = e.Length
    
       ' Position represents the current Position in the stream of the message being processed.
       ProgressBar2.Value = e.Position
    
       ' Display a message as well.
       Label1.Text = "Processing message " + e.PopMessage.Id
    End Sub
  8. Compile and run the application.
Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.