ImapBeginIdle Method

Note: This API is now obsolete.

Begins an asynchronous request for starting idling mode.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
[ObsoleteAttribute("This method is obsolete in .NET 4.5+. Use IdleAsync instead.")]
public IAsyncResult BeginIdle(
	AsyncCallback callback,
	Object state
)

Parameters

callback
Type: SystemAsyncCallback
The AsyncCallback delegate. You can leave it a null reference (Nothing in Visual Basic) if you do not use callbacks.
state
Type: SystemObject
An object that contains state information for this request. You can leave it a null reference (Nothing in Visual Basic).

Return Value

Type: IAsyncResult
An IAsyncResult that references the asynchronous idle process.
Exceptions
ExceptionCondition
MailBeeInvalidStateExceptionThere is already an operation in progress.
Remarks
This method is an asynchronous version of Idle. However, unlike Idle, using BeginIdle(AsyncCallback, Object) method usually does not require subscribing to Idling event because BeginIdle(AsyncCallback, Object) does not block and the application can use other techniques to keep UI responsive during idling.
Examples
This WinForms sample is an asynchronous version of the sample listed in Idle method documentation. Idling event is not used but UI still does not freeze during idling.
// To use the code below, import MailBee namespaces at the top of your code
using MailBee;
using MailBee.ImapMail;

// Put the code below inside your class.

// Imap object declared global because it's accessed from several methods.
Imap imp = null;

bool started = false;

// Monitor folder changes and save them in the log file.
private void imp_MessageStatus(object sender, ImapMessageStatusEventArgs e)
{
    ((Imap)sender).Log.WriteLine("Got " + e.StatusID + " status update");
}

// Start/stop idling.
// Add button1 on the form to make this sample working.
private void button1_Click(object sender, System.EventArgs e)
{
    if (started)
    {
        // Stop idling.
        imp.StopIdle();
        imp.EndIdle();

        // Disconnect from the server and revert to the original state.
        imp.Disconnect();
        button1.Text = "Go idle";
        started = false;
    }
    else
    {
        started = true;

        imp = new Imap();

        // Enable logging into a file.
        imp.Log.Filename = @"C:\Temp\log.txt";
        imp.Log.Enabled = true;
        imp.Log.Clear();

        // Connect to the server and check if IDLE is supported.
        imp.Connect("mail.domain.com");
        if (imp.GetExtension("IDLE") == null)
        {
            MessageBox.Show("IDLE not supported");
            imp.Disconnect();
            started = false;
        }
        else
        {
            // Login and select inbox.
            imp.Login("jdoe", "secret");
            imp.SelectFolder("Inbox");

            // Attach event handler.
            imp.MessageStatus +=new ImapMessageStatusEventHandler(imp_MessageStatus);

            button1.Text = "Stop idle";

            // Go idle in the background.
            imp.BeginIdle(null, null);
        }
    }
}

// Finish idling if the user closes the application.
// To make this method work, attach it to Closing event of the form.
private void Form1_Closing(object sender,
    System.ComponentModel.CancelEventArgs e)
{
    if (imp != null && imp.IsBusy)
    {
        imp.StopIdle();
        imp.EndIdle();
        imp.Disconnect();
    }
}
See Also