Я видел this aricle, в котором описывается реализация 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
.
Итак, где асинхронная часть здесь в этом примере?
так почему я вижу isThreadPool == true? –
из ссылки ", а затем сразу же вернуться из метода BeginProcessRequest" ..... return when? в начале или в конце этой функции? –
Это точно, потому что я не называю какой-либо метод XXX здесь. так где же часть ASYNC? –