Created
February 20, 2012 14:59
-
-
Save patridge/1869572 to your computer and use it in GitHub Desktop.
Session locking on MVC controller (via http://www.stefanprodan.eu/2012/02/parallel-processing-of-concurrent-ajax-requests-in-asp-net-mvc/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace YourNamespace.Controllers { | |
using System.Web.Mvc; | |
using System.Web.SessionState; | |
using System; | |
[SessionState(SessionStateBehavior.ReadOnly)] | |
public class AjaxParallelController : Controller { | |
public JsonResult GetWait(int i = -1) { | |
System.Threading.Thread.Sleep(5000); | |
return Json(new { id = i, type = "parallel", ts = DateTime.Now.Ticks }, JsonRequestBehavior.AllowGet); | |
} | |
} | |
public class AjaxSerialController : Controller { | |
public JsonResult GetWait(int i = -1) { | |
System.Threading.Thread.Sleep(5000); | |
return Json(new { id = i, type = "serial", ts = DateTime.Now.Ticks }, JsonRequestBehavior.AllowGet); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> | |
<script> | |
$(function() { | |
var log = function (data) { | |
console.log(data.type + "[" + data.i + "]: " + data.ts); | |
}; | |
for (i = 1; i <= 3; i++) { | |
$.ajax("/AjaxParallel/GetWait/?i=" + i, { | |
ifModified: false, | |
cache: false | |
}).done(function(data) { | |
log(data); | |
}); | |
} | |
for (i = 1; i <= 3; i++) { | |
$.ajax("/AjaxSerial/GetWait/?i=" + i, { | |
ifModified: false, | |
cache: false | |
}).done(function(data) { | |
log(data); | |
}); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment