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.
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 not 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.