lurscher
lurscher

Reputation: 26943

asynchronous mvc .net: how to return a view from async method

I'm starting to learn MVC.net and following this documentation.

In there, it is explained that an async controller will implement two methods, say the action is called News, then we will have a method called NewsAsync, which will return void, and a NewsCompleted, which will return a view, and that will be invoked once the outstanding operation returns.

My concern is that, i really don't see any point to an asynchronous operation that cannot return a view after the operation started. If the user will be unable to see any feedback whatsoever from the service until the asynchronous callback returns, then why bother with an asynchronous controller in the first place?

Is there any way to return an intermediate view after the async operation starts? Am i needlessly concerned about this apparent limitation? is there something i'm missing from the MVC.net?

Upvotes: 4

Views: 2549

Answers (2)

Tejs
Tejs

Reputation: 41246

The point of the asynchronous controller is to promote thread re-use so that if you have a particularly long running request that blocks on resources, you aren't going to be tying up the request queue. It has nothing to do with returning back information to the requesting party. To their end, they see no difference between an async controller and a normal controller.

It's not like it makes it more ajax friendly or whatever; a good example would be if you had a request start to render an image; traditionally, that request thread is going to be consumed while the CPU renders the image. With the asynchronous pattern, you can still be rendering the image, but that thread could be freed to service another web request until the render is complete, allowing greater throughput for your server.

Upvotes: 3

Chuck Conway
Chuck Conway

Reputation: 16435

One strategy is to set up polling on the client. Once the result has been generated the user will be notified.

Upvotes: 0

Related Questions