Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Feature: Asynchronous child actions not supported [601]

$
0
0
Attempting to use a child action that's marked as "async" in its method declaration results in the exception "HttpServerUtility.Execute blocked while waiting for an asynchronous operation to complete.".

Currently MVC 4 does not support asynchronous child actions, nor does it provide any graceful way of handling the request synchronously other than having to write a synchronous version of each action.

So far I've had to resort to hacks (http://stackoverflow.com/questions/13166180/force-synchronous-execution-of-asynchronous-action-in-asp-net-mvc-4/13210277#13210277) in order to force a blocking call.

A better solution might be to create a custom MvcHandler implementation that does this although MVC does not exactly make this easy with so many of the classes used in the current child action pipeline being internal/sealed.

Of course the ideal solution would be to have async child actions supported, but it would be nice to have a clean workaround until this is done.

There is also a request open on Uservoice for this, please vote. http://aspnet.uservoice.com/forums/41201-asp-net-mvc/suggestions/3233329-support-asynchronous-child-actions.

Code to reproduce:

public class HomeController : Controller
{
//
// GET: /Home/

public ActionResult Index()
{
return View();
}

[ChildActionOnly]
public async Task<ActionResult> Widget()
{
await Task.Delay(1000);
return Content("widget");
}

}

View:

@{
ViewBag.Title = "Index";
}

<h2>Index</h2>

@Html.Action("widget")
Comments: "There are several issues with the simplistic solution of calling the .Result on the method, as it can result in deadlocks/data corruption/or random exceptions." Can you be any more specific? What about if the child action has no choice but to call something down in a library that is async only. At what point is it safe to call the asynchronous method synchronously by wrapping it in .Result or similar?

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>