下面的JavaScript函数每15秒运行一次,并调用一个ASP.Net页面方法。它大约需要4-8秒才能完成。
我在同一页上还有另一个JavaScript函数,每2秒运行一次,但会被前一个方法周期性地阻塞,该方法需要更长的时间才能完成。
function get_case_list_data(count, max_id) {
PageMethods.GetCaseList(count, max_id, uid, is_agent, got_case_list_data, OnFailure);
}请如何防止ASP.Net页面方法调用阻止在同一页上执行其他JavaScript函数?
发布于 2016-06-29 00:36:47
使用浏览器调试工具,检查PageMethods.GetCaseList中使用的自动生成的代码,然后使用异步ajax调用来模拟调用,而不是阻塞调用。
PageMethods包装器只是为了方便起见,但这段代码通常很难看。您可以使用$.ajax或本机XmlHttpRequest手动称呼它为您自己。
异步= true;
如果您进行多个调用,ASP.NET会话可能会执行阻塞操作。使用javascript方法中的警报或console.log来确定阻塞的内容
function get_case_list_data(count, max_id) {
console.log("before call");
PageMethods.GetCaseList(count, max_id, uid, is_agent, got_case_list_data, OnFailure);
console.log("after call");
}
function got_case_list_data(){
console.log("in PageMethod success");
// -- updated --
// this could be blocking the call to/from other 2 second timer
// JS is single thread, so window.timeout and ajax callbacks will
// wait until the function is exited
// -- end update--
console.log("end of PageMethod success");
}-更新--
将asp.net会话设置为只读删除将同步线程的独占会话锁
https://stackoverflow.com/questions/38088407
复制相似问题