我看到这篇文章描述了实现IHttpAsyncHandler
.
看这部分:
public class MyAsyncHandler : IHttpAsyncHandler
{
///
/// The queue holds a list of asynchronous results
/// with information about registered sessions
///
public static List<myasyncresult> Queue;
static MyAsyncHandler()
{
// Initialize the queue
Queue = new List<myasyncresult>();
}
public IAsyncResult BeginProcessRequest(HttpContext context,
AsyncCallback cb, object extraData)
{
// Fetch the session id from the request
var sessionId = context.Request["sessionId"];
// Check if the session is already registered
if (Queue.Find(q => q.SessionId == sessionId) != null)
{
var index = Queue.IndexOf(Queue.Find(q => q.SessionId == sessionId));
// The session has already been registered,
// just refresh the HttpContext and the AsyncCallback
Queue[index].Context = context;
Queue[index].Callback = cb;
return Queue[index];
}
// Create a new AsyncResult that holds the information about the session
var asyncResult = new MyAsyncResult(context, cb, sessionId);
// This session has not been registered yet, add it to the queue
Queue.Add(asyncResult);
return asyncResult;
}
public void EndProcessRequest(IAsyncResult result)
{
var rslt = (MyAsyncResult) result;
// send the message to the recipient using
// the recipients HttpContext.Response object
rslt.Context.Response.Write(rslt.Message);
// reset the message object
rslt.Message = string.Empty;
}
}
这里的异步部分在哪里?我在这里看不到任何BeginXXX方法。
Thread.CurrentThread.IsThreadPoolThread
我还在第一行进行了 检查BeginProcessRequest
,它向我展示了TRUE
.
那么这个例子中的异步部分在哪里呢?