我已经实现了一个 IHttpAsyncHandler。我正在从具有该处理程序的小部件的网页进行大约 5 次不同的 AJAX 调用。
其中一个小部件需要大约 15 秒才能加载(因为数据库查询很大),其他小部件都应该在一秒钟内加载。处理程序以同步方式响应。
我得到的结果非常不一致。ProcessRequest 方法正在使用 Session 和其他类级别的变量。这是否会导致不同的请求使用相同的线程而不是每个线程都拥有?
我得到这个...
请求 1 ---> 响应 1 秒
请求 2 ---> 响应 14 秒
请求 3 ---> 响应 14.5 秒
请求 4 ---> 响应 15 秒
请求 5 ---> 响应 15.5 秒
但我正在寻找更像这样的东西......
请求 1 ---> 响应 1 秒
请求 2 ---> 响应 14 秒
请求 3 ---> 响应 1.5 秒
请求 4 ---> 响应 2 秒
请求 5 ---> 响应 1.5 秒
在没有发布太多代码的情况下,我对 IHttpAsyncHandler 方法的实现非常标准。
private AsyncProcessorDelegate _Delegate;
protected delegate void AsyncProcessorDelegate(HttpContext context);
IAsyncResult IHttpAsyncHandler.BeginProcessRequest(HttpContext context,
AsyncCallback cb, object extraData)
{
_Delegate = new AsyncProcessorDelegate(ProcessRequest);
return _Delegate.BeginInvoke(context, cb, extraData);
}
void IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
{
_Delegate.EndInvoke(result);
}
在我的 IHttpAsyncHandler.BeginProcessRequest 方法中放置一个调试断点,我可以看到该方法在最后一个 Process 完成之前不会被触发。
Also my machine.config has this entry... processModel autoConfig="true" with no other properties set.
I'm calling the handler like this...
$.ajax(
{
type: "GET",
url: "../HTML/HtmlHandler.ashx",
cache: true,
dataType: "text",
data: { html: name },
success: function(html) {
//$(function() {
//console.log(tabname);
//console.log("msg:" + msg);
$("#" + name + "holder").html(html);
//checkAllLoaded();
ClientHome_init('');
//});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$("#" + name + "holder").html("<span>Error retrieving widget.</span>");
//console.log("error:" + tabname);
//checkAllLoaded();
}
}
What else do I need to check for?