Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

First PageMethod blocks second page method from executing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roger Martin - 23 Jul 2007 20:32 GMT
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);
       }

   }
}
bruce barker - 23 Jul 2007 20:40 GMT
if you use sesson, then session locking prevents two concurrent
requests. turn off session in one of the requests.

-- bruce (sqlwork.com)

> 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
[quoted text clipped - 91 lines]
> }
>  
Roger Martin - 23 Jul 2007 21:16 GMT
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?
Roger Martin - 23 Jul 2007 22:02 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.