using System;using System.Collections.Generic;using System.Web;namespace HttpAsync{ ////// 封装web异步处理请求操作的方法 /// public abstract class MyHttpAsync : IHttpAsyncHandler { HttpContext context; object extraData; internal bool _isReusable = false; ////// 获取导航开始时传递的可选数据 /// public object ExtraData { get { return extraData; } //set { extraData = value; } } ////// 获取当前 HTTP 请求的所有特定信息对象 /// public HttpContext Context { get { return context; } //set { context = value; } } ////// 获取当前 HTTP 请求的 System.Web.HttpRequest 对象 /// public HttpResponse Response { get { return this.context.Response; } } ////// 获取当前 HTTP 请求的 System.Web.HttpRequest 对象 /// public HttpRequest Request { get { return this.context.Request; } } ////// web异步请求的入口 /// public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData) { this.context = context; this.extraData = extraData; myIAsyncResult mr = new myIAsyncResult(cb, new delRun(MyAsyncRun)); mr.myIAsyncResultRun(); return mr; } ////// 为异步进程提供的一种立即结束方法 /// public void EndProcessRequest(IAsyncResult result) { MyEndProcessRequest(result); } ////// 获取一个布尔值,它指示其他请求是否可以使用 HttpRemotingHandler。 /// public bool IsReusable { get { return _isReusable; } } ////// 处理 HTTP 请求。 /// /// public abstract void MyProcessRequest(HttpContext context); ////// 为异步进程提供的一种立即结束方法 /// public abstract void MyEndProcessRequest(IAsyncResult result); ////// 需要异步执行的操作 /// public abstract void MyAsyncRun(); ////// 处理 HTTP 请求。 /// public void ProcessRequest(HttpContext context) { MyProcessRequest(context); } } ////// 异步操作类 /// class myIAsyncResult : IAsyncResult { AsyncCallback cb; delRun dr; bool _IsCompleted = false; public object AsyncState { get { return null; } } public System.Threading.WaitHandle AsyncWaitHandle { get { return null; } } public bool CompletedSynchronously { get { return false; } } public bool IsCompleted { get { return _IsCompleted; } } public void myIAsyncResultRun() { dr(); _IsCompleted = true; cb(this); } public myIAsyncResult(AsyncCallback cb, delRun dr) { this.cb = cb; this.dr = dr; } } ////// 异步执行的委托 /// delegate void delRun();}