ReadAsync(CancellationToken)
This method returns a Task-based asynchronous version of OracleDataReader.Read().
Declaration
// C# public override Task<bool> ReadAsync(CancellationToken cancellationToken)
Parameters
cancellationToken - The input cancellation token which can be used by the application to cancel the task before command timeout occurs.
Return Value
Task<bool> object representing the asynchronous operation immediately without blocking the calling thread for the whole duration of the query execution
Implements
DbDataReader
Exceptions
InvalidOperationException - The connection is closed, or the reader is closed.
Example
using Oracle.ManagedDataAccess.Client;
using System;
using System.Threading;
namespace AsyncApp
{
class AsyncDemo
{
static async Task Main()
{
string connectionString = "User Id=HR; Password=<PASSWORD>; Data Source=oracle;";
OracleConnection oc = new OracleConnection(connectionString);
await oc.OpenAsync(CancellationToken.None);
OracleCommand cmd = oc.CreateCommand();
cmd.CommandText = "select * from demo_table";
OracleDataReader reader;
reader = await cmd.ExecuteReaderAsync();
while (await reader.ReadAsync(CancellationToken.None))
{
Console.WriteLine(reader.GetValue(0));
}
}
}
}