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.
Comments
Post a Comment