Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a sample I wrote that you could try:</p> <p>Controller:</p> <pre><code>public class HomeController : AsyncController { public ActionResult Index() { return View(); } public void SomeTaskAsync(int id) { AsyncManager.OutstandingOperations.Increment(); Task.Factory.StartNew(taskId =&gt; { for (int i = 0; i &lt; 100; i++) { Thread.Sleep(200); HttpContext.Application["task" + taskId] = i; } var result = "result"; AsyncManager.OutstandingOperations.Decrement(); AsyncManager.Parameters["result"] = result; return result; }, id); } public ActionResult SomeTaskCompleted(string result) { return Content(result, "text/plain"); } public ActionResult SomeTaskProgress(int id) { return Json(new { Progress = HttpContext.Application["task" + id] }, JsonRequestBehavior.AllowGet); } } </code></pre> <p>View:</p> <pre><code>&lt;script type="text/javascript"&gt; $(function () { var taskId = 543; $.get('/home/sometask', { id: taskId }, function (result) { window.clearInterval(intervalId); $('#result').html(result); }); var intervalId = window.setInterval(function () { $.getJSON('/home/sometaskprogress', { id: taskId }, function (json) { $('#progress').html(json.Progress + '%'); }); }, 5000); }); &lt;/script&gt; &lt;div id="progress"&gt;&lt;/div&gt; &lt;div id="result"&gt;&lt;/div&gt; </code></pre> <p>The idea is to start an asynchronous operation that will report the progress using <code>HttpContext.Application</code> meaning that each task must have an unique id. Then on the client side we start the task and then send multiple AJAX requests (every 5s) to update the progress. You may tweak the parameters to adjust to your scenario. Further improvement would be to add exception handling.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload