代码之家  ›  专栏  ›  技术社区  ›  ProfK

进程计数器页方法调用中止

  •  2
  • ProfK  · 技术社区  · 15 年前

    我的简单页面方法:

    [WebMethod]
    public static int GetProgress()
    {
        return (int)(HttpContext.Current.Session["ActivationResources.ImportProgress"] ?? 0);
    }
    

    我的客户端脚本:

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

    这个 updateImportProgress 函数被调用,但Firebug报告GetProgress的POST被“中止”。为什么会这样?我怀疑这是因为对静态方法的调用被我试图监视其进度的实际执行方法阻止了。中的断点 GetProgress 方法永远不会被击中。

    1 回复  |  直到 15 年前
        1
  •  0
  •   Bart Verkoeijen    14 年前

    我以前有过这个问题。作为一种解决方法,我在ashx文件中实现了代码,并避免了以这种方式接触同一页。也应该适用于您的代码,因为您只需报告一个会话变量。

    顺便说一句,注意在一个会话中运行两个请求时,代码会中断。当您在浏览器中打开同一页的多个选项卡时,可能会发生这种情况。