开发者

AJAX call being blocked

I've developed an C# AJAX based system with a reporting module, due to the more complex reports taking around 30 seconds to run I've built in a parallel AJAX call to report the progress of the report generation.

Report generator

At the start of the report I create an item in the cache

HttpContext.Current.Cache.Insert(appProgressName, new JSON.ReportProgress(), null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration );

which then gets updated periodically throughout the report generation

((JSON.ReportProgress)HttpContext.Current.Cache[appProgressName]).TimesheetsProcessed++;

then finally when the report has finished generating, it gets removed from the cache

HttpContext.Current.Cache.Remove(appProgressName);

Report progress checker

Then there is an AJAX call which runs every few seconds in the browser that calls the following web method on the server.

[WebMethod]
public static JSON.ReportProgress ReportProgress()
{
    string appProgressName = User.CurrentId() + "_ReportProgress";

    if ( HttpContext.Current.Cache[appProgressName] != null )
    {
        return (eServices.SIBSv2.JSON.ReportProgress)HttpContext.Current.Cache[appProgressName];
    }

    return null;
}

This then allows the client to calculate how far through the report generation is and display the progress bar updating.

The below image from Firebug shows it working correctly - with the initial report generation request and the progress checks following it.

AJAX call being blocked

This code works fine through Visual Studio 2010 using the development web browser at first, but stops working after a five or so report requests. When deployed to production (Using Windows 2003, IIS6, .net 4.0) the same behavior is displayed, showing the report generation progress for the first few attempts, then not working for further requests.

Checking the AJAX calls using Firebug when this issue starts happening I can see that the AJAX call made to check the progress does n开发者_运维百科ot complete until the primary AJAX call (generating the report) completes.

The issues with the asynchronously calls made to the progress checker AJAX method happen on both my development machine and the production environment. It seems to stop working after the website has been running a while.

To me this suggests something isn't getting tidied up following and causing it to stop working. After a recycle of the application pool on production, it'll start working again for a while.


It appears to be related to another StackOverflow question on Blocked AJAX calls from MVC, which was resolved by changing session behavior.

I appear to have solved my problem by:

1) Setting AJAX called to have readonly access to session state by default, setting <%@ Page Language="C#" Async="true" EnableSessionState="ReadOnly" %> at the top of my AJAX page.

2) Allow read/write access to session state when my report generator AJAX query is running HttpContext.Current.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.Required);

So far in production this appears to have solved the issue. I'll accept this answer if in 24 hours it's still running smoothly.

However I'm still puzzled by the blocking behavior not happening straight away, but only after a certain number of requests have been made.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜