EndExecuteReader Method (PgSqlCommand)
Ends an asynchronous invocation of the
ExecuteReader method.
In the example below an easiest way of executing an asynchronous operation is shown. First, all components are set up and a connection is opened. Second, a data retrieval operation is started. The operation state (done or in progress) is checked and a report is written to the console. At last query results are sent to
PgSqlDataReader and rendered to the console.
Public void Async_Exec(PgSqlConnection pgConnection)
{
PgSqlCommand pgCommand = new PgSqlCommand("SELECT * FROM Test.Dept",pgConnection);
Console.WriteLine("Starting asynchronous retrieval of data...");
pgConnection.Open();
IAsyncResult cres = pgCommand.BeginExecuteReader(null,null,CommandBehavior.Default);
if (cres.IsCompleted)
Console.WriteLine("Completed.");
else
Console.WriteLine("Have to wait for operation to complete...");
PgSqlDataReader pgReader = pgCommand.EndExecuteReader(cres);
try
{
while (pgReader.Read())
{
Console.WriteLine(pgReader.GetInt32(0) + " " + pgReader.GetString(1) + " " + pgReader.GetString(2));
}
}
finally
{
pgReader.Close();
pgConnection.Close();
}
}
Public Sub Async_Exec(ByVal pgConnection As PgSqlConnection)
Dim pgCommand As New PgSqlCommand("SELECT * FROM Test.Dept", pgConnection)
Console.WriteLine("Starting asynchronous retrieval of data...")
pgConnection.Open()
Dim cres As IAsyncResult = pgCommand.BeginExecuteReader(Nothing, Nothing, CommandBehavior.Default)
If cres.IsCompleted Then
Console.WriteLine("Completed.")
Else
Console.WriteLine("Have to wait for operation to complete...")
End If
Dim pgReader As PgSqlDataReader = pgCommand.EndExecuteReader(cres)
Try
While pgReader.Read()
Console.WriteLine(String.Concat(pgReader.GetInt32(0), " ", pgReader.GetString(1), " ", pgReader.GetString(2)))
End While
Finally
pgReader.Close()
pgConnection.Close()
End Try
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2