MailBee.NET Objects 3.1

Pop3.BeginDeleteMessages Method 

Begins an asynchronous request for flagging the specified range of messages for deletion from the server.

public IAsyncResult BeginDeleteMessages(
   int startIndex,
   int count,
   AsyncCallback callback,
   object state
);

Parameters

startIndex
The ordinal position (in the inbox) of the first message in the range being deleted.
count
Number of messages to be flagged for deletion, or -1 to indicate that all messages in the range startIndex to InboxMessageCount must be flagged for deletion.
callback
The AsyncCallback delegate. You can leave it a null reference (Nothing in Visual Basic) if you do not use callbacks.
state
An object that contains state information for this request. You can leave it a null reference (Nothing in Visual Basic).

Return Value

An IAsyncResult that references the asynchronous flagging the messages for deletion.

Remarks

This method is an asynchronous version of DeleteMessages.

Exceptions

Exception Type Condition
MailBeeInvalidStateException There is already an operation in progress.

Example

This WinForms sample demonstrates asynchronous flagging 5 last messages in the inbox for deletion. No callback function is used.

[C#]
// 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.

// The actual code.
private void Form1_Load(object sender, System.EventArgs e)
{
    Pop3 pop = new Pop3();

    // Let MailBee process events.
    pop.RaiseEventsViaMessageLoop = false;

    pop.Connect("pop.somehost.com");
    pop.Login("jdoe", "secret");

    // Initiate an asynchronous deletion attempt.
    pop.BeginDeleteMessages(pop.InboxMessageCount - 4, 5, 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);
    }

    // End the message flagging operation. If it's in progress at the moment 
    // this method starts, it will wait until it's done first.
    pop.EndDeleteMessages();

    // Disconnect from the server.
    pop.Disconnect();
}
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.Pop3Mail

' Put the code below inside your class.

' The actual code.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim pop As New Pop3

    ' Let MailBee process events.
    pop.RaiseEventsViaMessageLoop = False

    pop.Connect("pop.somehost.com")
    pop.Login("jdoe", "secret")

    ' Initiate an asynchronous deletion attempt.
    pop.BeginDeleteMessages(pop.InboxMessageCount - 4, 5, Nothing, Nothing)

    ' Simulate some lengthy work here...
    Dim i As Integer
    For i = 1 To 100
        ' 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

    ' End the message flagging operation. If it's in progress at the moment 
    ' this method starts, it will wait until it's done first.
    pop.EndDeleteMessages()

    ' Disconnect from the server.
    pop.Disconnect()
End Sub

See Also

Pop3 Class | MailBee.Pop3Mail Namespace | DeleteMessages