IAsyncResult实现
异步返回处理对象实现也很简单,实现一个Execute方法由队列执行,执行完成后通过callBack方法来通知处理完成.
public class AspxAsyncResult : IAsyncResult{
bool m_IsCompleted = false;
private IHttpHandler mHandler;
private HttpContext mContext;
private AsyncCallback m_Callback;
public AspxAsyncResult(HttpContext context, IHttpHandler handler, AsyncCallback cb)
{
mHandler = handler;
mContext = context;
m_Callback = cb;
}
#region IAsyncResult 成员
public object AsyncState
{
get { return null; }
}
public WaitHandle AsyncWaitHandle
{
get { return null; }
}
public bool CompletedSynchronously
{
get { return false; }
}
public bool IsCompleted
{
get { return m_IsCompleted; }
}
#endregion
public void Execute()
{
try
{
mHandler.ProcessRequest(mContext);
}
catch
{
}
finally
{
try
{
if (m_Callback != null)
m_Callback(this);
}
catch
{
}
m_IsCompleted = true;
}
}
}
本文导航
- 第1页: 首页
- 第2页: IAsyncResult实现
- 第3页: 测试效果和总结