I'm no MVC expert, but I'm fairly sure this is implementable; however, I don't know how to do it in MVC 4.
For testing, I'm using the default web app given when you create a site using VS 2012.
Consider, for simplicity, that HomeController.Index() is hit at exactly the same time by multiple users (for example 3). I want to execute a method that is mutexed so as only one will execute at a time; hence forcing them serially. I don't care what order. I know of the warnings about blocking a page and that everything should be async, but for this I need to block for a very short period of time.
public class HomeController : Controller {
private String dosomething() {
String str;
str = "SomeValue"; //<-- Will vary
return str;
}
public ActionResult Index() {
String str;
// How do I do implement the following, preferably with a timeout to be safe
Lock(dosomething);
str = dosomething();
unLock(dosomething);
return View();
}