2016-06-29 14 views
0

아래 JavaScript 함수는 15 초마다 실행되며 ASP.Net Page 메서드를 호출합니다. 완료하는 데 약 4 ~ 8 초가 소요됩니다.ASP.net PageMethod 호출이 다른 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 함수 실행을 차단하지 못하게하려면 어떻게해야합니까?

답변

1

브라우저 디버그 도구를 사용하고 PageMethods.GetCaseList에 사용 된 자동 생성 코드를 검사 한 다음 차단 된 대신 비동기식 ajax 호출로 호출을 모방합니다.

PageMethods 래퍼는 단지 편의를 위해 작성되었지만 일반적으로 코드는 꽤 추합니다. 항상 $ .ajax 또는 native XmlHttpRequest를 사용하여 직접 수동으로 호출 할 수 있습니다.

async = true;

여러 번 호출하는 경우 ASP.NET 세션이 차단을 수행 중일 수 있습니다.

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"); 
} 

차단을 결정하기 위해 자바 스크립트 방법에서 경고를 사용하거나 CONSOLE.LOG - updated--

asp.net 세션을 설정 스레드를 동기화 할 독점 세션 잠금을 제거 읽기 전용으로

+0

기본적으로 호출은 비동기 적이 지 않습니다? –

+0

PageMethod 호출 전과 성공 콜백 내에서 경고를 사용하여 테스트 할 수 있습니다. Google "aysnc PageMethods"는 기본적으로 aysnc 일 수 있으며 syncronouse가되도록 업데이트해야합니다. 어느 쪽이든이 블로그에는 시작하기 좋은 콘텐츠가 있습니다. http://abhijit-j-shetty.blogspot.com/2011/04/aspnet-ajax-calling-pagemethods.html – Steve

+0

$ ajax를 async = true로 시도했습니다. 동일한 결과 –