Пример асинхронного запроса
SqlConnection cn = new SqlConnection
("SERVER=sql2005;INTEGRATED SECURITY=True;"
+ "DATABASE=AdventureWorks;async=True");
SqlCommand cmd = new SqlCommand("SELECT * FROM Person.Contact", cn);
cmd.CommandType = CommandType.Text;
try
{
cn.Open();
IAsyncResult myResult = cmd.BeginExecuteReader();
while (!myResult.IsCompleted)
{
// Perform other code actions
}
// Process the contents of the reader
SqlDataReader rdr = cmd.EndExecuteReader(myResult);
// Close the reader
rdr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}