NextResultAsync(CancellationToken)
This method returns a Task-based asynchronous version of OracleDataReader.NextResult().
Declaration
// C#
public Task<bool> NextResultAsync(CancellationToken cancellationToken);Parameter
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.Data;
using System.Threading;
using System.Threading.Tasks;
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 = "BEGIN OPEN :1 FOR SELECT * FROM EMPLOYEES; OPEN :2 FOR SELECT * FROM DEPARTMENTS; END; ";
OracleParameter p1 = cmd.Parameters.Add("1", OracleDbType.RefCursor);
p1.Direction = ParameterDirection.Output;
OracleParameter p2 = cmd.Parameters.Add("2", OracleDbType.RefCursor);
p2.Direction = ParameterDirection.Output;
OracleDataReader reader = await cmd.ExecuteReaderAsync();
await reader.ReadAsync(CancellationToken.None);
Console.WriteLine(reader.GetValue(0));
Task task = reader.NextResultAsync(CancellationToken.None);
Console.WriteLine("Hello World");
await task;
await reader.ReadAsync(CancellationToken.None);
Console.WriteLine(reader.GetValue(0));
oc.Close();
}
}
}