I am just using the new Async Controller features in MVC 4 as described here http://www.asp.net/mvc/tutorials/mvc-4/using-asynchronous-methods-in-aspnet-mvc-4
If I have an action that may take 10-20 seconds to run I would like to provide some kind of status bar to notify the user of progress. Do the Async features have anything to help this out?
EDIT: I will take a stab at how I will try and do it and see if there are any better ways
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>