Devolución de llamada de Async Controller de ASP.NET MVC 4
Solo estoy usando las nuevas funciones de Async Controller en MVC 4 como se describe aquíhttp://www.asp.net/mvc/tutorials/mvc-4/using-asynchronous-methods-in-aspnet-mvc-4
Si tengo una acción que puede tardar entre 10 y 20 segundos en ejecutarse, me gustaría proporcionar algún tipo de barra de estado para notificar al usuario sobre el progreso. ¿Las funciones de Async tienen algo para ayudar a esto?
EDITAR: Voy a probar cómo lo intentaré y veré si hay formas mejores
public async Task<ActionResult> GizmosAsync()
{
return View("Gizmos", await GetGizmosAsync());
}
private void GetGizmosAsync()
{
for(int i=0; i<10; i++)
{
lock(_locker)
{
_statusMessage = String.Format("{0} of 10", i);
}
DoSomethingLongRunning();
}
}
public ActionResult Status()
{
return Json(new { Status = _statusMessage });
}
static readonly object _locker = new object();
static string _statusMessage = "";
....
<script>
setTimeout(displayStatus, 1000);
function displayStatus() {
$.post("/controller/status", function(data) {
alert(data.Status);
});
}
</script>