I read an article about async / await on Habré and came across the following line:

Despite the fact that in ASP.NET there is no dedicated UI thread, the code in the action-ah controllers cannot be executed by more than one workflow at a time.

Based on this line, I have questions:

  1. Why so limit the action ?
  2. How is this implemented внутрях ? lock in ActionInvoker'е ?

Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants cheops , aleksandr barakin , tutankhamun , user207618, HamSter 20 Sep '16 at 6:03 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Try to write more detailed questions. Explain exactly what you see the problem, how to reproduce it, what you want to get as a result, etc. - Nicolas Chabanovsky

1 answer 1

You just did not quite understand the idea that the author of the article tried to convey. He did not try to say that one specific Action method could not be executed in several threads - after all, it is quite obvious that this is not the case.

If you have a dozen simultaneous HTTP requests for the same Action, then this Action will be executed simultaneously in 10 different threads. There are no locks there.

The author of the article on Habré meant that one specific request — one specific Action call to process a specific request — will be executed by one specific workflow, to which the HttpContext of that request will be bound.

  • Yes, I already understood that I understood not so, but still “If you have a dozen simultaneous HTTP requests for the same Action, then this Action will be executed simultaneously in 10 different threads” is not quite right. There is a special case in which the action is not executed until the first one is completed - this is when two identical actions are requested from one connection, and apparently this follows from the http restriction, although I can’t be sure that this is the reason. I think this is exactly what the author had in mind - Qutrix
  • @Qutrix There are no such restrictions in http. Moreover, the very concept of action is a concept that exists within the framework of the server mvc handler. Http doesn't care if you call the MVC Action through it, or download the gif :) If you send two ajax requests from the browser, they will be processed by the server in parallel, in different streams. Even if you call the same Action. The only time that asp.net forcibly processes requests sequentially is to use the session state. - PashaPash
  • But let me give you an example: [SessionState (SessionStateBehavior.Disabled)] public class HomeController: Controller {public string Index () {var f = DateTime.Now.ToLongTimeString (); Thread.Sleep (10,000); return f; }} If you open two tabs with this action, the difference between their starts will be at least 10 seconds. Run if you do not believe. What is the explanation for this? - Qutrix
  • @Qutrix is ​​a very simple explanation - your browser sends requests with a matching url one by one. It is easy to check, take, for example, fiddler, and start interception - it is clear that the browser does not even try to send the next request without waiting for an answer to the previous one. But at the same time, if you replay immediately for a packet of requests in the fiddler, they will go to the server in parallel. It is possible to receive simultaneous requests even without fiddler — add any insignificant parameter to the url, different in different tabs (? Q = 1 and? Q = 2), without changing anything on the server - and the browser will send such requests at the same time. - PashaPash
  • @Qutrix here is the question on enSO about this behavior in chrome - stackoverflow.com/questions/14119367/… . - PashaPash