C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » Databases »

Asynchronous Command Execution in ADO.Net 2.0


Posted Date: 10 Jul 2008    Resource Type: Articles    Category: Databases
Author: Swapnil KumarMember Level: Silver    
Rating: 1 out of 5Points: 7



Asynchronous execution of the commands in ADO.Net 2.0 :-

Difference Between Synchronous Call and Asynchronous Call
A synchronous call blocks a process until the operation completes. Once each command is completed the process executes the next instruction. While in asynchronous calls, the process need not to wait for the completion of one command for the other when they are independent.

The asynchronous command execution feature in ADO.NET 2.0 is has improved data access efficiency and reduced latency and delays in the Web.

There are three design approaches for asynchronous model:

1. Polling :

Step 1) Start asynchronous command execution


IAsyncResult result = MyCommand.BeginExecuteReader()


Step 2) Wait until execution is complete:


while (! result.IsCompleted)
{
// execute other code here
}


Step 3) Fetch results


SqlDataReader reader = MyCommand.EndExecuteReader(result )


2. Wait :

Step1) Start one or more asynchronous commands as an array of IAsyncResult instances:


IAsyncResult resultx = MyCommand.BeginExecuteReader()


Step2) Wait for each command to complete


for(int i=0; i < result_array.Length, i++)
{
index = WaitHandle.WaitAny(result_array,
timeout, true);
switch(index) {
case 0: SqlDataReader reader =
MyCommand.EndExecuteReader(resultx);
// ...etc...




3. Callback :

Step1) Start execution, specifying callback and passing command as the AsyncState:


MyCommand.BeginExecuteReader(new AsyncCallback(MyCallback), cmd)



Step2) Provide a callback handler :


void MyCallback(IAsyncResult result)
{
SqlCommand cmd = (SqlCommand) result.AsyncState;
SqlDataReader reader = cmd.EndExecuteReader(result);
}


By using any of the three models, you can achieve the asynchronous calling in ADO.Net.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Asynchronous Execution of Commands in ADO.NET 2.0  .  Asynchronous Execution of Commands in ADO.NET  .  Asynchronous Execution of Commands  .  Asynchronous Command Execution in ADO.NET 2.0  .  Asynchronous Command Execution in ADO.NET  .  Asynchronous Command Execution  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Database Files in SQL Server
Previous Resource: T-SQL Guidelines Part 1
Return to Discussion Resource Index
Post New Resource
Category: Databases


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use