I'm not sure if I'm even asking the question correctly, so bear with me; here's what I'm dealing with:
In my MVC4 project (targetting .Net 4.5.1) If I do await SomeAsyncMethod(...)
, then the task completes in the background but appears to never return. I believe this has something to do with the thread being returned to the pool and then resuming on a different thread. The workaround I've been using is to use Thread.Run(() => SomeTask).Result;
.
So, I find myself having to do Thread.Run(() => SomeAsyncMethod).Result;
a lot in my MVC projects lest I end up with deadlocks. Isn't this just another syntax for running the Task synchronously? I'm not sure if this is a limitation of MVC 4 (versus MVC 5) or if that's just how the api works. Am I essentially gaining nothing in terms of asynchronicity by doing this?
We've written a small library here where all of the operations are async Task<T>
and it is in a separate assembly, so at least we can use it "properly" elsewhere (e.g. a window phone app), but this MVC 4 project is a consumer of said library, and it feels like we're basically stepping around the benefits of async/await in order to avoid deadlocks, so I'm looking for help in seeing the bigger picture here. It would help to better understand what I'm gaining by consuming asynchronous tasks in a synchronous mannger (if anything), what I'm losing, if there's a solution that gives me back the ability to await these tasks without deadlocking, and whether or not the situation is different between MVC 4 and MVC 5+
TIA