When calling BeginInvoke on a delegate, the action is executed on a separate thread. If called in ASP.NET does it use a CLR worker thread? Or does it use an IIS worker thread?
If the latter, then I will need to employ an asynchronous ASP.NET pattern to ensure the action is executed on a CLR worker thread. But I would rather not do that if the action ends up there upon BeginInvoke.
You can call methods asynchronously in four different ways using the BeginInvoke() and EndInvoke() methods of the Delegate class. The four different ways are using the EndInvoke pattern, WaitHandle, Polling pattern and using a Callback Pattern. In this article, we will see the Delegate EndInvoke Pattern.
Delegates enable you to call a synchronous method in an asynchronous manner. When you call a delegate synchronously, the Invoke method calls the target method directly on the current thread. If the BeginInvoke method is called, the common language runtime (CLR) queues the request and returns immediately to the caller.
To do this, you need to supply an instance of the AsyncCallback delegate as a parameter to BeginInvok(). This delegate will call a specified method automaticaly when the asynchronous call has completed. The method that AsyncCallback will invoke must taking IAsyncResult as a sole parameter and return nothing.
The simplest way to execute a method asynchronously is to start executing the method by calling the delegate's BeginInvoke method, do some work on the main thread, and then call the delegate's EndInvoke method. EndInvoke might block the calling thread because it does not return until the asynchronous call completes.
it uses a CLR worker thread.
as described in here
To begin with, ASP.NET uses the process-wide CLR thread pool to service requests (for more background on the CLR thread pool, see the .NET column in this issue).
EDIT:
another resource is this blog
Unfortunately, the thread used by BeginInvoke is actually taken from the same worker thread pool that is used by ASP.Net to handle Page Requests
Thread usage/management is a bit different in IIS6, IIS7 and IIS 7.5.
Pretty detail and updated explanation here:
ASP.NET Thread Usage on IIS 7.5, IIS 7.0, and IIS 6.0
Not sure if this answers your question but a good read anyways.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With