First PageMethod blocks second page method from executing

G

Guest

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

}
}
 
B

bruce barker

if you use sesson, then session locking prevents two concurrent
requests. turn off session in one of the requests.

-- bruce (sqlwork.com)
 
G

Guest

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?
 
G

Guest

Okay, I found the EnableSession property on the WebMethod attribute, so I can
turn off session for page methods like this:

[System.Web.Services.WebMethod(EnableSession=false)]
public static void WebMethod2()
{
System.Threading.Thread.Sleep(5000);
}

However, doing so for one - or both - of the page methods does not solve the
problem. The documentation says that the default value is false, so the above
is actually no different than omitting the parameter. In other words, session
is already disabled for page methods by default.

I confirmed that disabling session at the page level allows the page methods
to run correctly, but this is not an option for me. Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top