c# - BackgroundWorker in MVC3 application freezes UI -


i'm developing mvc3 based web application, @ 1 point needs cache large amount of data external database. process takes 10-30 min (depending on traffic) put in backgroundworker. when click particular button on webpage, using ajax access other method in controller, depending on returned value proper information displayed on user interface.

controller:

if (isdblocked()) {     return this.json(new      {         success = false,         message = "there update requested other user on way."     }); }  this.model.dataupdatebegin();  return this.json(new { success = true }); 

model:

public void dataupdatebegin()     {         var backgroundworker = new backgroundworker                                    {                                        workersupportscancellation = false,                                        workerreportsprogress = true                                    };          backgroundworker.dowork += this.dataupdateworkerdowork;         backgroundworker.progresschanged += this.dataupdaterworkerprogresschanged;         backgroundworker.runworkercompleted += this.dataupdaterworkerrunworkercompleted;          if (this.dataupdatelockdb(true))         {             backgroundworker.runworkerasync();         }     } 

now when update, ui still freezes. while debuging controller can see, starts backgroundworker , instantly continues return statement (with success = true), finishes, , nothing else happens (returned message never reaches webpage).

i can see page other browser/user , works ok, particular thread locked several minutes (not entire 10-30 min, it's unlocked after 5 min - timeout?)

my question is, did wrong , how fix it. expect backgroundworker run in background, , free user move around page wherever wish. making entry in database , making external application fetch , work (in real background) not option me.

do not use background worker this. yes, work done within thread, still in scope of web request. web requests not ment alive 30 minutes, there plenty of things can go wrong (timeouts, app pool restart, other iis behaviour..)

if have type of long-running task, should in worker - windows service, maybe console application, etc. , web start (console) or set done (message queue, azure queue)

also, hope not locking database (you method isdblocked()) 30 minutes? import in transaction , use proper isolation level (read commited) db work time , changes there instantly when import finishes.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -