Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>On the javascript side, the function that begins the progress check won't fire until after the successful completion of <code>HandleBatchRequest</code> request. The third parameter of <code>$.post()</code> is what is fired after a successful request.</p> <p>You'll either need to have your C# controller return the task ID right away, and ferry off the database insert into another thread/background worker (more on this below). Or have Javascript randomly generate the taskId and pass into the C# controller.</p> <p>From there, as Brad mentioned, you don't want to do setInterval with a ajax request inside of it. Since AJAX is asyncronous, you could be waiting a while before the server returns a response. To prevent multiple requests from happening at once and causing undo stress on the backend server, you'll want to do something like:</p> <pre><code>var taskId = 0; $.post('/SendBatch/HandleBatchRequest', {}, function(r) { taskId = r; // set task id from $("#monitors").append($("&lt;p id='" + taskId + "'/&gt;")); CheckProgress(); }, 'html'); function CheckProgress() { $.post("SendBatch/Progress", { id: taskId }, function (progress) { if (progress &gt;= 100) { updateMonitor(taskId, "Completed"); } else { updateMonitor(taskId, progress + "%"); setTimeout(function() { CheckProgress() }, 1000); } } </code></pre> <p>On the C# side of things, The controller is instantiated on every web request, so when you go check the progress, <code>tasks</code> will be empty. You'll need to off load the actual records into some sort of background worker/thread that does the actual leg work of inserting the records from the controller. If you're doing this pretty often, you may want to look into some sort of background service installed on the server itself that continuously runs to optimize things and give you the best flexibility going forward.</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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    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