首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何防止ASP.net PageMethod调用阻止其他javascript函数调用

如何防止ASP.net PageMethod调用阻止其他javascript函数调用
EN

Stack Overflow用户
提问于 2016-06-29 00:30:45
回答 1查看 652关注 0票数 0

下面的JavaScript函数每15秒运行一次,并调用一个ASP.Net页面方法。它大约需要4-8秒才能完成。

我在同一页上还有另一个JavaScript函数,每2秒运行一次,但会被前一个方法周期性地阻塞,该方法需要更长的时间才能完成。

代码语言:javascript
复制
function get_case_list_data(count, max_id) {
   PageMethods.GetCaseList(count, max_id, uid, is_agent, got_case_list_data, OnFailure);
}

请如何防止ASP.Net页面方法调用阻止在同一页上执行其他JavaScript函数?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-29 00:36:47

使用浏览器调试工具,检查PageMethods.GetCaseList中使用的自动生成的代码,然后使用异步ajax调用来模拟调用,而不是阻塞调用。

PageMethods包装器只是为了方便起见,但这段代码通常很难看。您可以使用$.ajax或本机XmlHttpRequest手动称呼它为您自己。

异步= true;

如果您进行多个调用,ASP.NET会话可能会执行阻塞操作。使用javascript方法中的警报或console.log来确定阻塞的内容

代码语言:javascript
复制
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会话设置为只读删除将同步线程的独占会话锁

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38088407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档