c# - How do I update a web page asynchronously as it processes records -


i have .net web app written in c#. front end, click button kicks off long process. looping logic appears in lower tier. every time loops, use delegate pass next tier same; using delegate pass message ui. if step through this, appears work, page isn't updated until end. put literal needs updated in update panel. missing something.

public delegate void processedeventhandler(object sender, string msg); public delegate void longtimetaskdelegate();  public class fileapplicationframework {     static list<application> lstapplications = new list<application>();     public event processedeventhandler onrecordprocessed;      //constructor     public fileapplicationframework()     {         //get test data         testdatamgt otestmgt = new testdatamgt();         lstapplications = otestmgt.getapplicants();     }      public void fileapplicationwithoutregistering()     {         try         {             int = 0;              foreach (application oapplication in lstapplications)             {                 if (i < 5)                 {                                    dothework(oapplication); //this long process                                     onrecordprocessed(this, "record number");                      i++;                 }             }         }         catch (exception)         {          }     }      public void dothework(application oapplication)     {         system.threading.thread.sleep(10000);     } } 

then going middle tier...

 public delegate void displaymessageeventhandler(object sender, string msg);      public class fileapplicationtests     {         public event displaymessageeventhandler onreadytobedisplayed;          public string fileapplication()         {             string msg = string.empty;              try             {                 fileapplicationframework filer = new fileapplicationframework();                 filer.onrecordprocessed += new processedeventhandler(printmsg);                 filer.fileapplicationwithoutregistering();              }             catch (exception ex)             {                 msg = "failed." + " " + datetime.now.tostring() + " " + ex.message;             }                         {                 //browser.close();             }              return msg;         }          private void printmsg(object sender, string msg)         {             onreadytobedisplayed(this, msg);         }     } } 

and ui....

click button , code runs...

fileapplicationtests fileapplicationpagetest = new fileapplicationtests();    fileapplicationpagetest.onreadytobedisplayed += new displaymessageeventhandler(writetolog); fileapplicationpagetest.fileapplication();  

and function should update literal:

private void writetolog(object sender, string log_entry)     {                   literal1.text += log_entry + "<br/>";             updatepanel1.update();     } 


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -