SQL 文の非同期実行を終了し、要求された ULDataReader を返します。
Visual Basic Public Function EndExecuteReader( _ ByVal asyncResult As IAsyncResult _ ) As ULDataReader
C# public ULDataReader EndExecuteReader( IAsyncResult asyncResult );
asyncResult BeginExecuteReader への呼び出しによって返される System.IAsyncResult。
要求されたローの取り出しに使用する ULDataReader オブジェクト (ExecuteReader と同じ動作)。
BeginExecuteReader を呼び出すごとに、EndExecuteReader を呼び出す必要があります。呼び出しは、BeginExecuteReader が返されてから行います。ADO.NET はスレッドに対応していないため、各自で BeginExecuteReader が返されたことを確認する必要があります。EndExecuteReader に渡される System.IAsyncResult は、完了した BeginExecuteReader 呼び出しから返されるものと同じでなければなりません。EndExecuteReade を呼び出して、BeginExecuteNonQuery への呼び出しを終了すると、エラーになります。逆についても同様です。
コマンドの実行中にエラーが発生すると、EndExecuteReader が呼び出されるときに例外がスローされます。
実行の完了を待機するには、4 通りの方法があります。
Call EndExecuteReader EndExecuteReader を呼び出すと、コマンドが完了するまでブロックします。次に例を示します。
' Visual Basic Dim cmd As ULCommand = new ULCommand( _ "SELECT * FROM Departments", conn _ ) Dim res As IAsyncResult res = _ cmd.BeginExecuteReader() ' perform other work ' this will block until the command completes Dim reader As ULDataReader = _ cmd.EndExecuteReader( res ) // C# ULCommand cmd = new ULCommand( "SELECT * FROM Departments", conn ); IAsyncResult res = cmd.BeginExecuteReader(); // perform other work // this will block until the command completes ULDataReader reader = cmd.EndExecuteReader( res ); |
Poll the IsCompleted property of the IAsyncResult IAsyncResult の IsCompleted プロパティをポーリングできます。次に例を示します。
' Visual Basic Dim cmd As ULCommand = new ULCommand( _ "SELECT * FROM Departments", conn _ ) Dim res As IAsyncResult res = _ cmd.BeginExecuteReader() While( !res.IsCompleted ) ' do other work End While ' this will block until the command completes Dim reader As ULDataReader = _ cmd.EndExecuteReader( res ) // C# ULCommand cmd = new ULCommand( "SELECT * FROM Departments", conn ); IAsyncResult res = cmd.BeginExecuteReader(); while( !res.IsCompleted ) { // do other work } // this will block until the command completes ULDataReader reader = cmd.EndExecuteReader( res ); |
Use the IAsyncResult.AsyncWaitHandle property to get a synchronization object IAsyncResult.AsyncWaitHandle プロパティを使用して同期オブジェクトを取得し、その状態で待機できます。次に例を示します。
' Visual Basic Dim cmd As ULCommand = new ULCommand( _ "SELECT * FROM Departments", conn _ ) Dim res As IAsyncResult res = _ cmd.BeginExecuteReader() ' perform other work Dim wh As WaitHandle = res.AsyncWaitHandle wh.WaitOne() ' this will not block because the command is finished Dim reader As ULDataReader = _ cmd.EndExecuteReader( res ) // C# ULCommand cmd = new ULCommand( "SELECT * FROM Departments", conn ); IAsyncResult res = cmd.BeginExecuteReader(); // perform other work WaitHandle wh = res.AsyncWaitHandle; wh.WaitOne(); // this will not block because the command is finished ULDataReader reader = cmd.EndExecuteReader( res ); |
Specify a callback function when calling BeginExecuteReader BeginExecuteReader の呼び出し時にコールバック関数を指定できます。次に例を示します。
' Visual Basic Private Sub callbackFunction(ByVal ar As IAsyncResult) Dim cmd As ULCommand = _ CType(ar.AsyncState, ULCommand) ' this won't block since the command has completed Dim reader As ULDataReader = cmd.EndExecuteReader() End Sub |
' elsewhere in the code Private Sub DoStuff() Dim cmd As ULCommand = new ULCommand( _ "SELECT * FROM Departments", conn _ ) Dim res As IAsyncResult = _ cmd.BeginExecuteReader( _ callbackFunction, cmd _ ) ' perform other work. The callback function ' will be called when the command completes End Sub |
// C# private void callbackFunction( IAsyncResult ar ) { ULCommand cmd = (ULCommand) ar.AsyncState; // this won't block since the command has completed ULDataReader reader = cmd.EndExecuteReader(); } |
// elsewhere in the code private void DoStuff() { ULCommand cmd = new ULCommand( "SELECT * FROM Departments", conn ); IAsyncResult res = cmd.BeginExecuteReader( callbackFunction, cmd ); // perform other work. The callback function // will be called when the command completes } |
コールバック関数は別のスレッドで実行するため、スレッド化されたプログラム内でのユーザ・インタフェースの更新に関する通常の注意が適用されます。
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |