A Task-based asynchronous version of the
TdCommand.ExecuteReader method. Executes the SQL statement (
TdCommand.CommandText property) using one of the
Data.CommandBehavior enumeration members. The cancellation token may be use to cancel the execution of the
TdCommand
.
Parameters
- behavior
- One of the Data.CommandBehavior enumerations values.
- cancellationToken
- A Threading.CancellationToken used to indicate that the asynchronous operation should be canceled.
Return Value
Returns a Task<TdDataReader> representing the asynchronous operation.
The following example creates a
TdConnection
and executes a SQL statement. It returns a
TdDataReader
. When the calling method closes the
TdDataReader
, the corresponding
TdConnection
is closed.
public TdDataReader ExecuteQuery(string connectionString, string commandText)
{
TdConnection cn = new TdConnection(connectionString);
cn.Open();
TdCommand cmd = new TdCommand(commandText, cn);
TaskCompletionSource tcs = new TaskCompletionSource();
Task<TdDataReader> task = cmd.ExecuteReaderAsync(CommandBehavior.CloseConnection, tcs.Token);
// perform other tasks
// wait for the result
TdDataReader reader = task.Result;
return reader;
}
Target Platforms: Windows 7, Windows 8, Windows 8.1, Windows 10, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2