asp.net - Why is controller thread is blocked if I use the session? -


i have pretty simple controller:

  public class homecontroller : controller     {         public actionresult index()         {             session["somedata"] = "123";             return view();         }          [httppost]         public actionresult longtest()         {             thread.sleep(5000);             return json(new { text = datetime.now.tostring("hh:mm:ss.fff") + " - longtest"});         }          [httppost]         public actionresult cantanswer()         {             return json(new { text = datetime.now.tostring("hh:mm:ss.fff") + " - cantanswer"});         }     } 

i use these methods client's side way:

<script type="text/javascript">     $(document).ready(function () {         $('#btnlongoperation').click(function () {             $.post("/home/longtest", null, function (data) {                 $('#result').text(data.text);             }, "json");         });          $('#btnwnotwork').click(function () {             $.post("/home/cantanswer", null, function (data) {                 $('#result').text(data.text);             }, "json");         });     }); </script> <div>     <input id="btnlongoperation" type="button" value="long operation"/>     <input id="btnwnotwork" type="button" value="won't work"/> </div> <div id="result"> 

if click first button , without waiting 5 seconds click second button second action won't called. if remove string using session in init method see actions able called without waiting each other. however, once use session object not see result of second action untill first 1 finished. can explain behavior of asp.net mvc?

this caused session locking. in essence, each request uses session state places lock on until done reading. subsequent requests cannot access session until previous request releases lock.

the purpose of ensure integrity of session data. example, happen if request needed write session , request b needed read, requests issued simultaneously? data b reads unpredictable have no way of knowing whether pre or post-write.

read here more information:

http://www.timvasil.com/blog14/post/2008/04/16/handling-multiple-simultaneous-requests-from-a-user-in-aspnet.aspx


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -