Reputation: 10395
If i'm looking to use TPL async at my data layer, must i also use Task<T>
on my MVC controller?
In other words, for async to work with .NET MVC, must it be implemented from the time the request begins in order for it to work on deeper execution layers? Or is there still a benefit to having Task<T>
at my DAL/web request level even if i'm using a sync controller?
Upvotes: 1
Views: 108
Reputation: 171246
If you don't use an async controller you will have to wait on a task at some point. At this point the main advantage is gone: Reducing the number of blocked threads.
Of course this is not true if you run multiple async activities at the same time. That would reduce the number of blocked threads from N to one. (If N = 1 there is no benefit, just damage).
Note that async is not faster by default. Its main purpose in ASP.NET is to gain scalability at the extreme end - with 100s of concurrent requests. Only then will it be faster or scale higher.
So if you have a "usual" number of concurrent requests (like < 100), just go synchronous and don't worry about all of this.
Upvotes: 1