views:

36

answers:

1

I have read about executing asynchronous operations and i found that it can be done at the SQL command executions side(that is handled during executing SQL command by adding wait handle that waits for AsynchResult) or from the UI execution side(which is done by using delegate that points to a method then begin invoke methods asynchronously) like the following :

SQL side(by using wait handle and DELAYFOR in the SQL command): http://msdn.microsoft.com/en-US/library/yws6262h%28v=VS.80%29.aspx

UI side: http://msdn.microsoft.com/en-US/library/2e08f6yc%28v=VS.80%29.aspx

but i don't know which is better with respect to the performance and runtime?

Can any one tell me the differences with respect to the performance perspective? and which is better also this technique or thread pool queue technique ?

Thanks in advance

+1  A: 

Hi,

Assuming by "SQL side" you mean the BeginXXX EndXXX methods on the SqlCommand object, and the UI meaning simply a delegate executed asynchronously - there is no performance difference provided by simply using one versus the other. A performance difference between the two will only be in relation to the code you run - the SQL side will only execute the command asynchronously, the UI side might have a lot of other code you provide.

In a lot of cases, it's simply enough to provide the async actions at a higher level than the SQL command. In some cases, such as your data access layer wanting to start many commands at once, it will then be good to use the SqlCommand methods.

Hopefully that's somewhere near what you are after.

Note that executing a delegate asynchronously (Delegate.BeginInvoke) or a BeginXXX method will use a ThreadPool thread. The differences between using a delegate versus the thread pool are quickly outlined here:

http://www.toadz.dk/2010/01/delegate-begininvoke-vs-threadpool-queueuserworkitem/

Adam
So what is the difference between delegate asynchronously(.BeginInvoke) and thread pooling which use threads(QueueUserWorkItem) ?
Ahmy
Here is a quick explanation: http://www.toadz.dk/2010/01/delegate-begininvoke-vs-threadpool-queueuserworkitem/
Adam
+1 for your innovative explanation
Ahmy