c# - MVC 4 Async Action isn't handling multiple requests between wait -


i trying test mvc4 async controller actions have read here: http://www.asp.net/mvc/tutorials/mvc-4/using-asynchronous-methods-in-aspnet-mvc-4

below controller:

public class homecontroller : asynccontroller {     //     // get: /home/      public async task<actionresult> index()     {         writeonfile("here dude. time: " + datetime.now.tostring("hh:mm:ss:fff"));         await task.delay(10000);         return view();     }      private void writeonfile(string text)     {         using (mutex mutex = new mutex(false, "tempfile"))         {             mutex.waitone();             using (var writer = new streamwriter(@"d:\temp\temp.txt", true))             {                 writer.writeline(text);             }             mutex.releasemutex();         }     } } 

i testing opening 5 browser tabs pointing ~/home/index , refreshing them @ once.

below output getting:

  • here dude. time: 09:09:04:108
  • here dude. time: 09:09:14:129
  • here dude. time: 09:09:24:160
  • here dude. time: 09:09:34:176
  • here dude. time: 09:09:44:200

the time-stamps 10 seconds apart. means each request being handled after previous 1 completes. synchronous controller actions do, hoped asynchronous controller actions handle requests while waiting. why async not working in above example? i'm doing wrong?

i using iis 8.5 in windows 8.1 .net 4.5.

thanks in advance.

asp.net mvc depends upon session state default. asp.net block concurrent requests same source if depend upon session state. why have seeing concurrent requets being executed once @ time. see this question further explanation.

furthermore, asynccontroller obsolete. use normal controller instead, method wrap in async/task/task automatically async in normal code.

you have 2 choices: disable dependency upon session or use web api default not depend upon session , run concurrently.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -