0 out of 2 rated this helpful - Rate this topic

IHttpAsyncHandler Interface

Defines the contract that HTTP asynchronous handler objects must implement.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)
public interface IHttpAsyncHandler : IHttpHandler

The IHttpAsyncHandler type exposes the following members.

  Name Description
Public property IsReusable Gets a value indicating whether another request can use the IHttpHandler instance. (Inherited from IHttpHandler.)
Top
  Name Description
Public method BeginProcessRequest Initiates an asynchronous call to the HTTP handler.
Public method EndProcessRequest Provides an asynchronous process End method when the process ends.
Public method ProcessRequest Enables processing of HTTP Web requests by a custom HttpHandler that implements the IHttpHandler interface. (Inherited from IHttpHandler.)
Top

An IHttpAsyncHandler class can be associated with a file name extension or a particular URL by a configuration file, in the httpHandlers configuration section. The ASP.NET infrastructure will then instantiate and call the handler when the corresponding request is received. Alternatively, the handler can be defined in an .ashx file and when the corresponding request is received for the .ashx file the hander will be executed.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Upload with progress using Asynchronous HTTP Handler
http://managemedia.codeplex.com/
Best way is not to create your own thread or use threadpool thread
Having an async handler is only useful if to process the request you have other async steps available (such as an off-box database call or a long hard drive read that you can call async as well.) To do this properly you would chain async methods (ie BeginProcessRequest would call FileStream.BeginRead with the same (or seperate) callback and handle accordingly.)

Sometimes it's useful to create a FIXED number of threads to bound the IIS Asp.net threads that hand you the request. An example of this is if you have 1 thread constantly polling some other service and don't want all N requests threads blocking to essentially do the same operation. This one fixed thread can complete all outstanding N requests.

So please don't
- Pass them off to the threadpool. You'd might as well use IHttpHandler
- Create your own thread pool for each request (this is actually worse than using threadpool.) The example is contribed because the only work being done is sleep. You can make this thread efficient by having 1 sleep thread that goes around and finishes requests once they've been there for 20 seconds.
- Sleep or Wait on the Handle or call EndFoo unless your callback (that you specified in BeginFoo) has been called. This blocks the thread anyways and essentially makes your IHttpAsyncHandler an IHttpHandler
Best IHttpAsyncHandler Article I've Found
Here's a great example of how to implement an Asynchronous Http Handler.  I don't know this page doesn't refer to it.

The article points out that the best way of implementing the whole IHttpAsyncHandler "Stack" is to create your own thread manually and not use the delegate "BeginInvoke" or the ThreadPool.QueueUserWorkItem.

http://msdn.microsoft.com/en-us/magazine/cc164128.aspx#S4