Click here to Skip to main content
15,881,424 members
Articles / Web Development / ASP.NET

ASP.NET Advanced Generic Handler ASHX

Rate me:
Please Sign up or sign in to vote.
4.74/5 (49 votes)
9 Jun 2013CPOL5 min read 320.2K   10.2K   138  
Take your Generic Handlers to the next level...
@{
    ViewBag.Title = "SimpleTest";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>SimpleTest</h2>

    <div id="divSimpleTest">
		<input type="button" value="Start simple test" onclick="SimpleTest()" />
		<span id="total"></span>
		<div id="result"></div>


		<script type="text/javascript">
			var tracking = [];
			var numberOfRequests = 100;
			var finished = 0;
			var $total = $('span#total');
			tracking = [];

			var d = new Date();

			function SimpleTest() {
				tracking.push({ idx: finished, ms: new Date().getTime() });

				$.ajax({
					url: '/Tests/SimpleMethod',
					type: 'GET',
					cache: false,
					data: { idx: finished },
					success: function (data) {
						tracking.push({ idx: data, ms: new Date().getTime() });
						finished++;
						$total.html(finished);

						if (finished == numberOfRequests)
							showResult();
						else
							SimpleTest();
					},
					error: function () {
						$("#divSimpleTest").append('0');
					}
				});
			};

			function showResult() {
				var $result = $('#result');
				var $list = $("<ul id='list'></ul>");
				var sum = 0;
				var count = 0;
				$.each(tracking, function (idxS, start) {
					$.each(tracking, function (idxE, end) {
						if (idxE > idxS && start.idx == end.idx) {
							var average = end.ms - start.ms;
							sum += average;
							$list.append("<li>" + average + "ms</li>");

							count++;
						}
					});
				});

				$list.append("<li>Average: " + (sum / numberOfRequests) + "ms</li>");
				$result.empty().append($list);
			}
		</script>

    </div>

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
Architect
Switzerland Switzerland
Senior IT Consultant working in Switzerland as Senior Software Engineer.

Find more at on my blog.

Comments and Discussions