How exactly does AsyncController
avoid using an ASP.NET worker thread? If I use the 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 doesn't use an ASP.NET worker thread. How is this possible?
I looked a bit into 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 worker thread? Surely both of these use a thread pool thread, and surely there is only one thread pool in an ASP.NET worker process?
According to MSDN,
The Web server gets a thread from the thread pool (the worker thread) and schedules it to handle an incoming request. This worker thread initiates an asynchronous operation.
The worker thread is returned to the thread pool to service another Web request.
When the asynchronous operation is complete, it notifies ASP.NET.
But for anything non-trivial, it sounds like initiates an asynchronous operation will still require a thread to run on. Only in extremely simple cases (like using the BCL to download web content) will it be completely unwound and/or completely IOCP bound, right?
I'm asking partly because I see all these Chat Servers implemented using AsyncController
and if all they do is "wait for new messages" I don't understand how that can be done on a non-threadpool thread.