Click here to Skip to main content
15,886,873 members
Articles / Web Development / HTML5

AJAX Progress Bar for ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.80/5 (33 votes)
11 Jun 2014CPOL4 min read 170.3K   8K   51  
Async Progress Indicator with Messages and OnComplete Event
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace hmlib.Web.UI.Controls
{
	public partial class Progress
	{
		static List<Progress> _list = new List<Progress>();
		public static Progress Find(string id)
		{
			Progress.CleanUp();
			return _list.Find(a => a.ID == id);
		}
		public static Progress FindOrCreate(string id)
		{
			return Progress.Find(id) ?? new Progress(id);
		}
		public static object GetResponse(string progressId)
		{
			Progress item = Progress.Find(progressId);
			if (item == null) return null;
			if (item.NewLines.Count > 1000) throw new Exception("Too many lines");
			var result = new
			{
				value = item.Value,
				lines = item.NewLines.ToArray()
			};
			item.NewLines.Clear();
			return result;
		}
		internal static void CleanUp()
		{
			_list.RemoveAll(a => (DateTime.Now - a.CreatedOn).TotalDays > 1);
			//_list.RemoveAll(a => a.Value == 1 && (DateTime.Now - a.ChangedOn).TotalSeconds > 5);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) FDK
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions