SqlDataReader.ReadAsync(CancellationToken) 方法

定義

非同步版本的 Read(),這個版本會將 SqlDataReader 前移至下一筆記錄。An asynchronous version of Read(), which advances the SqlDataReader to the next record.

取消語彙基元可用於要求在命令逾時之前捨棄作業。The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. 例外狀況將經由傳回的 Task 物件回報。Exceptions will be reported via the returned Task object.

public:
 override System::Threading::Tasks::Task<bool> ^ ReadAsync(System::Threading::CancellationToken cancellationToken);
public override System.Threading.Tasks.Task<bool> ReadAsync (System.Threading.CancellationToken cancellationToken);
override this.ReadAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<bool>

參數

cancellationToken
CancellationToken

取消指令。The cancellation instruction.

傳回

表示非同步作業的工作。A task representing the asynchronous operation.

例外狀況

在工作完成前,對同一個執行個體呼叫 ReadAsync(CancellationToken) 不止一次。Calling ReadAsync(CancellationToken) more than once for the same instance before task completion.

在連接字串中指定了 Context Connection=trueContext Connection=true is specified in the connection string.

SQL Server 於執行命令文字時傳回錯誤。SQL Server returned an error while executing the command text.

備註

如果 ExecuteReaderAsyncbehavior 參數設定為 DefaultReadAsync 會在傳回工作之前讀取整個資料列。If the behavior parameter of ExecuteReaderAsync is set to Default, ReadAsync reads the entire row before returning the Task.

如需詳細資訊(包括程式碼範例),請參閱 .NET Framework Data Provider 中 SQL Server 的非同步程式設計,請參閱非同步程式設計For more information, including code samples, about asynchronous programming in the .NET Framework Data Provider for SQL Server, see Asynchronous Programming.

適用於

另請參閱