I have a fairly long process running in a standard postback. Then I have the following page method to return progress to a repeating JavaScript function that is supposed to report on progress.
My simple page method:
[WebMethod]
public static int GetProgress()
{
return (int)(HttpContext.Current.Session["ActivationResources.ImportProgress"] ?? 0);
}
My clientside script:
function startProgress() {
window.setInterval(updateImportProgress(), 500);
}
var importProgress = 0;
function updateImportProgress() {
//debugger;
PageMethods.GetProgress(function (result, response, context) {
if (result == importProgress) {
$("#messageLabel").append(" .");
}
else {
$("#messageLabel").html("Busy importing resources - " + result + "%");
}
importProgress = result;
});
}
The updateImport开发者_StackOverflow中文版Progress
function is called, but Firebug reports that the POST for GetProgress is 'aborted'. Why could this be? I suspect that this is because the call to the static method is blocked by the actual executing method whose progress I am trying to monitor. A breakpoint in the GetProgress
method is never hit.
I had this issue before. As a workaround I've implemented the code in an ashx file and avoided that way to touch the same page. Should work for your code as well, as you simply report a session variable.
Btw, note that your code breaks when you have 2 requests running in a single session. That can happen when you open multiple tabs of the same page in the browser.
精彩评论