IAsyncResult實現(xiàn)
異步返回處理對象實現(xiàn)也很簡單,實現(xiàn)一個Execute方法由隊列執(zhí)行,執(zhí)行完成后通過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;
}
}
}
本文導(dǎo)航
- 第1頁: 首頁
- 第2頁: IAsyncResult實現(xiàn)
- 第3頁: 測試效果和總結(jié)