c# - WPF only binds data to datagrid between user actions. How to force update to datagrid? -


user can perform action , add data collection bound datagrid , works fine.

but when there long running process has multiple records added collection never see datagrid updated until process over. doing wrong? new sure issue simple.

   private observablecollection<statusentry> _collse = new observablecollection<statusentry>();     public observablecollection<statusentry> collse     {         { return _collse; }         set         {             _collse = value;            // notifypropertychanged("collse");         }     }    collse.add(new statusentry() { timestamp = datetime.now, comment = "started: translating file datatable" });                 datatable dt = excelhelper.readasdatatable(tbfilename.text);                 collse.add(new statusentry() { timestamp = datetime.now, comment = "complete: translating file datatable" }); 

edit:

more here tried.. still not update ui until end though

  private void btnprocessfile_click(object sender, routedeventargs e)     {         //this should happen button pressed         threadstart job = new threadstart(() =>         {             (int = 0; < 20; i++)             {                 // new thread puts ui operations in dispatching queue                 dispatcher.invoke(dispatcherpriority.normal, new action(() =>                 {                     collse.add(new statusentry() { timestamp = datetime.now, comment = "happy tools started" });                 }));             }         });          thread thread = new thread(job);         thread.start();            //the minute of processing here..... 

i made mistake of asking question without understanding basics , therefore coding on place not sure doing. think got now. article helped simple mind understand here..

the main point understand wpf has main thread , ui thread , how go 1 other allow access ui.

http://elegantcode.com/2009/07/03/wpf-multithreading-using-the-backgroundworker-and-reporting-the-progress-to-the-ui/


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -