By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,781 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,781 IT Pros & Developers. It's quick & easy.

First PageMethod blocks second page method from executing

P: n/a
I am executing an AJAX page method that is a long running task. After
starting the first method, I execute a second page method to retrieve the
status of the task. It works fine in an empty web application, but when I
paste the code into my main application (~10 projects, maybe 100 files) the
behavior changes. What happens is the second page method will not begin
executing until the first one finishes. In other words, the page methods
execute serially.

For the life of me I cannot figure out the difference between my main app
and the empty app where it works. Nothing is different in web.config. What
could possibly be going on in my main app that might cause this behavior?

FYI, I am ultimately trying to implement Dino Esposito's article "Canceling
Server Tasks with ASP.NET AJAX" in the July 2007 MSDN issue. His sample code
behaves the same way as my code below (works fine in empty app but runs
serially in my main app).

ASPX page:

<%@ Page Language="C#" AutoEventWireup="true"
Codebehind="testnomaster.aspx.cs" Inherits="GalleryServerPro.Web.test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">

function startTask()
{
PageMethods.WebMethod1(WebMethod1Completed, WebMethod1Failed);

PageMethods.WebMethod2(WebMethod2Completed, WebMethod2Failed);
}

function WebMethod1Completed(results, context, methodName)
{

}

function WebMethod1Failed(results, context, methodName)
{
alert("failed");
}

function WebMethod2Completed(results, context, methodName)
{

}

function WebMethod2Failed(results, context, methodName)
{
alert("failed");
}

</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="true">
</asp:ScriptManager>
<input type="button" onclick="startTask()" value="Start" />
</form>
</body>
</html>

Code behind:

using System;
using System.Web.UI;

namespace GalleryServerPro.Web
{
public partial class test : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

[System.Web.Services.WebMethod]
public static void WebMethod1()
{
System.Threading.Thread.Sleep(10000);
}

[System.Web.Services.WebMethod]
public static void WebMethod2()
{
System.Threading.Thread.Sleep(10000);
}

}
}

Jul 23 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
if you use sesson, then session locking prevents two concurrent
requests. turn off session in one of the requests.

-- bruce (sqlwork.com)

Roger Martin wrote:
I am executing an AJAX page method that is a long running task. After
starting the first method, I execute a second page method to retrieve the
status of the task. It works fine in an empty web application, but when I
paste the code into my main application (~10 projects, maybe 100 files) the
behavior changes. What happens is the second page method will not begin
executing until the first one finishes. In other words, the page methods
execute serially.

For the life of me I cannot figure out the difference between my main app
and the empty app where it works. Nothing is different in web.config. What
could possibly be going on in my main app that might cause this behavior?

FYI, I am ultimately trying to implement Dino Esposito's article "Canceling
Server Tasks with ASP.NET AJAX" in the July 2007 MSDN issue. His sample code
behaves the same way as my code below (works fine in empty app but runs
serially in my main app).

ASPX page:

<%@ Page Language="C#" AutoEventWireup="true"
Codebehind="testnomaster.aspx.cs" Inherits="GalleryServerPro.Web.test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">

function startTask()
{
PageMethods.WebMethod1(WebMethod1Completed, WebMethod1Failed);

PageMethods.WebMethod2(WebMethod2Completed, WebMethod2Failed);
}

function WebMethod1Completed(results, context, methodName)
{

}

function WebMethod1Failed(results, context, methodName)
{
alert("failed");
}

function WebMethod2Completed(results, context, methodName)
{

}

function WebMethod2Failed(results, context, methodName)
{
alert("failed");
}

</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="true">
</asp:ScriptManager>
<input type="button" onclick="startTask()" value="Start" />
</form>
</body>
</html>

Code behind:

using System;
using System.Web.UI;

namespace GalleryServerPro.Web
{
public partial class test : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

[System.Web.Services.WebMethod]
public static void WebMethod1()
{
System.Threading.Thread.Sleep(10000);
}

[System.Web.Services.WebMethod]
public static void WebMethod2()
{
System.Threading.Thread.Sleep(10000);
}

}
}
Jul 23 '07 #2

P: n/a
You are right that session was causing the problem. Thanks!

But how can I turn off session for one of the requests? I know I can set
EnableSessionState="false" for the page directive, but the web page *does*
use session, so this won't work. However, neither of my page methods need
session, so I am happy to turn off session for those. Is this possible, or
can I only disable session at the page level?
Jul 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.