I'm working with AsyncController in .NET4.5 project. The controller is implemented using MVC 3 pattern where 2 methods are used in order to achieve asynchrony. Here is an example:
public class PortalController : AsyncController {
public void NewsAsync(string city) {
AsyncManager.OutstandingOperations.Increment();
NewsService newsService = new NewsService();
newsService.GetHeadlinesCompleted += (sender, e) =>
{
AsyncManager.Parameters["headlines"] = e.Value;
AsyncManager.OutstandingOperations.Decrement();
};
newsService.GetHeadlinesAsync(city);
}
public ActionResult NewsCompleted(string[] headlines) {
return View("News", new ViewStringModel
{
NewsHeadlines = headlines
});
}
}
In the above code I need to call:
private async Task<Foo> doWorkAsync(string bar) {
// do work async
}
I can't refactor the existing code to make Controller return Task<ActionResult> at this time, as it looks like it will take a lot of time. So my question is what would be the best way to call an async method from within NewsAsync()?