Click or drag to resize

Working with async/await

With the release of 4.0 SphinxConnector.NET has become fully asynchronous.

Note Note
Each asynchronous SphinxQL method call needs to be awaited, before invkoing another SphinxQL method.
Asynchronously retrieving Data via the SphinxQLDataReader

C#
using (SphinxQLConnection connection = new SphinxQLConnection("Data Source=localhost;Port=9306"))
{
    SphinxQLCommand command = new SphinxQLCommand("SELECT * from sakila WHERE MATCH(@match)", connection);
    command.Parameters.Add("@match", "room");

    await connection.OpenAsync();

    using (SphinxQLDataReader dataReader = await command.ExecuteReaderAsync())
    {
        while (await dataReader.ReadAsync())
        {
            Console.WriteLine(dataReader.GetInt64("id"));
        }
    }
}

C#
using (SphinxQLConnection sphinxQLConnection = new SphinxQLConnection(connectionString))
{
    SphinxQLCommand sphinxQLCommand = sphinxQLConnection.CreateCommand("INSERT into rt_index (id, title, content) VALUES (@rtid, @title, @content)");

    sphinxQLCommand.Parameters.Add("rtid", 1, SphinxType.UInt);
    sphinxQLCommand.Parameters.Add("title", "My Title", SphinxType.String);
    sphinxQLCommand.Parameters.Add("content", "My Content", SphinxType.String);

    await sphinxQLConnection.OpenAsync();

    await sphinxQLCommand.ExecuteNonQueryAsync();
}
Note Note
For some genaral guidance on working with async/await, I recommend this execellent article by Stephen Cleary.