Call the EndExecuteReader method EndExecuteReader メソッドを呼び出すと、コマンドが完了するまでブロックします。次に例を示します。
' Visual Basic
Dim cmd As ULCommand = new ULCommand( _
"SELECT * FROM Departments", conn _
)
Dim res As IAsyncResult res = _
cmd.BeginExecuteReader()
' Perform other work
' This blocks until the command completes.
Dim reader As ULDataReader = _
cmd.EndExecuteReader( res )
対応する C# 言語のコードを次に示します。
// C#
ULCommand cmd = new ULCommand(
"SELECT * FROM Departments", conn
);
IAsyncResult res = cmd.BeginExecuteReader();
// Perform other work
// This blocks until the command completes
ULDataReader reader = cmd.EndExecuteReader( res );
' Visual Basic
Dim cmd As ULCommand = new ULCommand( _
"SELECT * FROM Departments", conn _
)
Dim res As IAsyncResult res = _
cmd.BeginExecuteReader()
While( !res.IsCompleted )
' Perform other work
End While
' This blocks 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 ) {
// Perform other work.
}
// This blocks until the command completes.
ULDataReader reader = cmd.EndExecuteReader( res );
' 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 does not block because the command is finished.
Dim reader As ULDataReader = _
cmd.EndExecuteReader( res )
対応する C# 言語のコードを次に示します。
// C#
ULCommand cmd = new ULCommand(
"SELECT * FROM Departments", conn
);
IAsyncResult res = cmd.BeginExecuteReader();
// Perform other work.
WaitHandle wh = res.AsyncWaitHandle;
wh.WaitOne();
// This does not block because the command is finished.
ULDataReader reader = cmd.EndExecuteReader( res );
Specify a callback function when calling the BeginExecuteReader method 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
' is called when the command completes.
End Sub
対応する C# 言語のコードを次に示します。
// 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
// is called when the command completes.
}