ImapBeginSortedSearch Method

Note: This API is now obsolete.

Begins an asynchronous request for searching the currently selected folder for messages meeting the specified criteria and sorting them accordingly the specified sort condition.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.2.0 build 630 for .NET 4.5
[ObsoleteAttribute("This method is obsolete in .NET 4.5+. Use SortedSearchAsync instead.")]
public IAsyncResult BeginSortedSearch(
	bool returnUids,
	string searchCondition,
	string charset,
	string orderBy,
	AsyncCallback callback,
	Object state


Type: SystemBoolean
If true, search results will be returned as UidCollection; otherwise, as MessageNumberCollection.
Type: SystemString
Search expression in IMAP4 language, or a null reference (Nothing in Visual Basic) to make the method return all messages in the folder.
Type: SystemString
Charset used in searchCondition, or a null reference to use US-ASCII setting.
Type: SystemString
Sorting order expression in IMAP4 language, or a null reference (Nothing in Visual Basic) to make the method downgrade to the regular BeginSearch(Boolean, String, String, AsyncCallback, Object).
Type: SystemAsyncCallback
The AsyncCallback delegate. You can leave it a null reference (Nothing in Visual Basic) if you do not use callbacks.
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 search process.
MailBeeInvalidStateExceptionThere is already an operation in progress.
This method is an asynchronous version of SortedSearch(Boolean, String, String, String).
This console sample demonstrates asynchronous search of messages arrived into the Inbox folder since yesterday and sorting them by their Subject line.
using System;
using MailBee;
using MailBee.ImapMail;

class Sample
    // A callback function.
    private static void SortedSearchCallback(IAsyncResult result)
        // Extract values from state object.
        Imap imp = (Imap)((object [])result.AsyncState)[0];
        bool sortAvail = (bool)((object [])result.AsyncState)[1];

        // Display the outcome.
        Console.WriteLine("SORT capability is " + (!sortAvail ? "NOT " : "") + "available");
            Console.WriteLine("UIDs found: " + ((UidCollection)imp.EndSortedSearch()).ToString());
        catch (Exception e)
            // Catching exception here is recommended. Because callback function is a separate
            // thread, unhandled exception would silently terminate it without any message to
            // the user (and it would be hard to understand what exactly happened).
            Console.WriteLine("Exception occurred: " + e.Message);

    // The actual code.
    static void Main(string[] args)
        Imap imp = new Imap();

        // Connect to the server, login and select inbox.
        imp.Login("jdoe", "secret");

        // Set to true if SORT extension is available.
        bool sortAvail = (imp.GetExtension("SORT") != null);

        // If SORT is supported, order messages by SUBJECT field. If SORT is not supported,
        // orderBy criteria will not be set and SortedSearch will downgrade to the regular Search.
        string orderByCriteria = sortAvail ? "SUBJECT" : null;

        // Initiate an asynchronous request for getting UIDs of messages received since yesterday,
        // sorted accordingly orderByCriteria.
        IAsyncResult ar = imp.BeginSortedSearch(true,
            "SINCE \"" + ImapUtils.GetImapDateString(DateTime.Today.AddDays(-1)) + "\"",
            null, orderByCriteria,
            new AsyncCallback(SortedSearchCallback), new object[] {imp, sortAvail});

        // Simulate some lengthy work here. At the same time,
        // folder selection is executed on another thread.

        // If the folder selection attempt is still in progress,
        // then wait until it's finished.
        while (imp.IsBusy) ar.AsyncWaitHandle.WaitOne();

        // Disconnect from the server.
See Also