Reputation: 53
I'm a fresh in asp.net mvc? and i found that the MVC engine provide the async action function. That means you can realize it in a APM way. But I'm very curious about it that I can send a request by ajax. Why should I use the async action? How to use it?
Thank you for you hellp. David Peng
Upvotes: 0
Views: 236
Reputation: 3153
It's pushed as a best practice for scalability. A webserver can only take in so many web requests at a time. The async model frees up the thread so it can process an additional incoming request while the current request is being processed.
Don't confuse this with parallel processing. It's not that at all. If you attempted to do two queries against the same datacontext with async methods you would get exceptions.
The commitment is that you have to use the Async equivilents that Linq provides like AnyAsyc, FirstOrDefaultAsyc, ToListAsyc. If you are calling domain services these services must return as Task<Result>
and then when you call your domain service you put the await keyword in front.
For most applications it's pretty straight forward. What catches many people off guard is they start to think parallelism and try doing multiple operations side by side with one data context and that won't work. Just remember, all your doing is freeing up the server to take in another request and you free it up where you put await before the method.
Upvotes: 1