I\'m interested in running a long process, I want to update the UI as soon as results start coming in and not wait for it to finish.
How would I go about this? I\'ve
This article seems to describe what you want, simple and w/o SignalR:
ASP.NET MVC 3: Async jQuery progress indicator for long running tasks
Controller:
public class HomeController : Controller { private static IDictionary tasks = new Dictionary();
public ActionResult Index()
{
return View();
}
public ActionResult Start()
{
var taskId = Guid.NewGuid();
tasks.Add(taskId, 0);
Task.Factory.StartNew(() =>
{
for (var i = 0; i <= 100; i++)
{
tasks[taskId] = i; // update task progress
Thread.Sleep(50); // simulate long running operation
}
tasks.Remove(taskId);
});
return Json(taskId);
}
public ActionResult Progress(Guid id)
{
return Json(tasks.Keys.Contains(id) ? tasks[id] : 100);
}
}
View: