I working on an ASP.NET MVC which is loading its data completely via a WCF service. What my model does is just call the WCF service. The controller then passes the model to the view. I read in this article that it is always better to do async calls if you can. However I am still not sure which call to use. What would happen if the data form the service takes a while to load? Does it mean that my controller code will keep running and if the data is not there when the return statement is reached my controller will return an empty view, which could also cause a null pointer exception because of the view accessing unpopulated model fields?
Take the 2-minute tour
×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
|
If your controller returns a Task then you will be fine. If you are on C# 5.0 you can use async/await to make your code more maintainable than what is shown in the article. Basically your code will look like this
or you can just not care and use all synchronous calls. The downside of using synchronous calls is that your throughput would suffer. You will be able to handle 200 requests per second instead of 50K requests per second (and I am pulling these numbers out of thin air). Of course in most cases you simply don't care because your project never does more than 20 requests per second. |
|||||||||
|