Today, we make a function to query tables with a certain amount of data. However, there are many related effects in the footer. In order. Poor user experience. Therefore, asynchronous queries are considered. It is to do other threads during Operation query. I was thinking about multithreading. But because it is a web program. Therefore, give up.
Considering that the asynchronous query function of ado.net has never been used, let's make a demo to check the performance.
Static void Main (string [] args)
{
String constr = @ "Data Source = ***. ***. ***. * **; uid = *****; pwd = *****; database = *****; Asynchronous Processing = true ";
Using (SqlConnection con = new SqlConnection (constr ))
{
Using (SqlCommand cmd = new SqlCommand ("waitfor delay '00: 00: 10' select top 50 * from TEshow", con) // delay of 10 seconds to test the effect
{
Con. Open ();
Console. WriteLine ("sssssss ");
IAsyncResult iay = cmd. BeginExecuteReader ();
Console. WriteLine ("bbbbbbb ");
SqlDataReader dr = cmd. EndExecuteReader (iay );
While (dr. Read ())
{
String msg = string. format ("the first number is: {0}, the second number is: {1}", dr [0]. toString (), dr [1]. toString ());
Console. WriteLine (msg );
}
Console. ReadLine ();
}
}
}
It feels okay.