views:

55

answers:

1

in this sample, two threads created; a worker thread created by BeginInvoke and an I/O completion thread created by SendAsync method.

but another author in his UnsafeQueueNativeOverlapped example, don't recommend this.

i want to use SendAsync or ...Async in an asp.net page and i want to use PageAsyncTask. however, its BeginEventHandler requires AsyncResult to be returned which SendAsync does not return.

afaik, event based async pattern is the most recommended way so how could we call SendAsync or any ...Async methods without creating two threads and hurting the performance?

+2  A: 

Actually if you used the beginIvoke and endInvoke for delegates or ThreadPool.WorkerItem it will not make any difference in your application because they are using the same thread that asp.net uses throw the iis so now you have only 2 solution to make async calls first u will write your own threading classes (but be careful ) second use the PageAsyncTasks(recommended) this one much more safe and it's designed to work perfectly with asp.net

it's not about hurting the performance as much as it's about how and when to use asnyc tasks if your process really take much time until it finish (because IIS will wait until all processes finish even the asnyc ones then start rendering) then you have to go to async solution instead it will make a draw back in performance

Note:

there is a difference between AddOnPreRenderCompleteAsync and RegisterAsyncTask in there implementation they look the same but in the second one

  1. you have access to the current http context ,impersonation, culture and profile data etc
  2. you can run many tasks in parallel
  3. you have timeout event and you can determine timeout in the page attribute
  4. you can call RegisterAsyncTask several times in one request to register several async operations
Amgad Fahmi