| Working with async/await |
With the release of 4.0 SphinxConnector.NET has become fully asynchronous.
Note |
---|
Each asynchronous SphinxQL method call needs to be awaited, before invkoing another SphinxQL method.
|
Asynchronously retrieving Data via the SphinxQLDataReader 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"));
}
}
}
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();
}