ajax - Implementing a Progress bar for long running task implemented with an ASP.NET MVC 2 AsyncController -


after reading documentation on asynccontrollers in asp.net mvc 2, wondering what's best way implement ajax progress bar in scenario. seems bit odd tutorial not cover @ all.

i guess implementing ajax progress bar involves requires additional action method returns status of current task. however, not sure best way exchange information on status of task between worker threads , action method.

my best idea far put information on curent progress session dictionary along unique id, , share id client can poll status. perhaps there easier way did not notice.

what's best way this?

thanks,

adrian

very interesting question! seems not task asynccontroller. async controllers designed long-running single-http-query operations @ server-side. when using async action, release asp.net worker thread during long-running operation(s) , allow serve other requests while operation performed. client-side point of view doesn't matter, async controller or not. client single http request.

you need redesign using long-running queries service in application. here example of controller, serve such workflow:

public class longoperationscontroller : controller {     public actionresult startoperation(operationdata data)     {          guid operationid = guid.newguid(); // unique identifier operation         operationsservice.dostartoperation(operationid, data); // service starts perform operation using separate thread         return new jsonresult(operationid); // operation id should sent client allow progress monitoring     }      public actionresult getoperationstatus(guid operationid)      {         var status = operationsservice.getstatus(operationid); // method returns object, describes status of operation (e.g. progress, current task etc.)         return new jsonresult(status); // returning client     }      public actionresult getoperationresult(guid operationid)     {         var result = operationsservice.getoperationresult(operationid); // should throw exception if operation not yet completed         return new jsonresult(result);     }      public actionresult clearoperation(guid operationid)     {         operationsservice.clearoperationresult(operationid); // should delete operation result if handled client         return true;     } } 

and here client-side code, interact controller:

var operationid; function startoperation(data) {     $.post('/longoperations/startoperation', data, function(response) {         operationid = response; // store operationid         startoperationmonitoring(); // start     }, 'json'); }  function startoperationmonitoring() {     // todo : periodically call updateoperationstatus() check status @ server-side }  function updateoperationstatus() {     // todo : result of getoperationstatus action controller      // todo : if status 'running', update progress bar value server, if 'completed' - stop operation monitoring , call finishoperation() }  function finishoperation() {     // todo : result of getoperationresult action controller , update ui     // todo : call clearoperation action controller free resources } 

this basic concept, there missed items here, hope main idea. it's how design components of system, example:

  • use singleton operationsservice, or not;
  • where , how long operation result should stored (db? cache? session?);
  • is required manually release resources , when client stopped monitor operation (user closed browser) etc.

best luck!


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -