How does AsyncController avoid using ASP.NET workflow?

How exactly AsyncController avoid using ASP.NET workflow? If I use an event-based pattern (pseudo-code):

 [AsyncTimeout(60000)] public void WaitForWakeUp() { AsyncManager.OutstandingOperations.Increase(); EventRaisedElsewhere += state => { AsyncManager.OutstandingOperations.Decrease(); return Content("Woke up because of " + state); }; } 

... then, according to Clay Lenharts , it does not use the ASP.NET workflow. How is this possible?

I looked a bit at the AsyncController source code, but didn’t understand anything, except that it uses IAsyncResult alot and does QueueUserWorkItem in some places.

But how can BeginInvoke and QueueUserWorkItem not use an ASP.NET workflow? Of course, both of them use a thread-stream thread, and of course, in ASP.NET workflow there is only one thread pool?

According to MSDN,

The web server receives the stream from the thread pool (worker thread) and plans to process the incoming request. This worker thread initiates an asynchronous operation.

The workflow is returned to the thread pool to serve another Web request.

When the asynchronous operation is completed, it notifies ASP.NET.

But for something non-trivial, it seems that the initiators of the asynchronous operation still require the thread to work. Only in extremely simple cases (for example, using BCL to download web content) will it be fully deployed and / or fully tied to IOCP, right?

I ask in part because I see that all these chat servers are implemented using AsyncController , and if all they do is “wait for new messages”, I don’t understand how this can be done in a thread other than threadpool.

+4
source share
1 answer

You seem to be right. It uses an asp.net thread to initiate an asynchronous call, but this thread terminates and returns to the pool. The async process then starts on another thread from the workflow pool before notifying asp.net that the thread needs to process the result.

it is more efficient because the asp.net thread pool limits incoming connections, so releasing them as quickly as possible allows you to quickly deal with a large number of incoming connections.

At least as I see it.

Edit I do not think this is absolutely true. There is only one thread pool, as defined in the structure, but you can create as many other threads as you want and create your own thread pool, different from the background thread pool.

I believe what is happening here. There are a small number of workflows associated with requests. These worker threads spawn threads in the background pool for processing asynchronous requests.

Simon

0
source

All Articles