asp.net mvc - Why do you use async if you don't promote it to the controller? -
i'm trying figure out how use async/await in c# in asp.net mvc. main point seems helps asp.net releasing threads worker pool when doing io (so can process other stuff). doing have promote async/await modifier method doing io call controller action (you better have few layers).
is there point in using feature without promoting async/await controller ? (by adding task.wait after call async method instance).
the answer yes think using task.wait in action not idea because can lead dead lock situation
consider guide :)
where
figure 3 common deadlock problem when blocking on async code
public static class deadlockdemo { private static async task delayasync() { await task.delay(1000); } // method causes deadlock when called in gui or asp.net context. public static void test() { // start delay. var delaytask = delayasync(); // wait delay complete. delaytask.wait(); } }
but if add configureawait(false)
delayasync()
this
await task.delay(1000).configureawait(false)
then can avoid dead lock said in article
aside performance, configureawait has important aspect: can avoid deadlocks. consider figure 3 again; if add
“configureawait(false)”
line of code in delayasync, deadlock avoided. time, when await completes, attempts execute remainder of async method within thread pool context. method able complete, completes returned task, , there’s no deadlock. technique particularly useful if need gradually convert application synchronous asynchronous.
Comments
Post a Comment