mysql - Prevent Locking of UI Thread -


i have datagrid on main page full of employees. each employee has "in" status - modified based on whether employee in building or not.

i need consistently update datagrid people entering or leaving building throughout day. means sending mysql queries somewhere between every 1-5 seconds until user clicks on button navigate page.

i have tried simple , obvious solution, while loop freezes , locks ui. how can create loop runs , queries mysql without locking ui?

edit: attempted answer

        public void periodiccall()         {             var employeeds = new employeedataservice();             int = 1;             timer timer = new timer(                 state => {                     employees = employeeds.handleemployeeselect();                     filteredview = collectionviewsource.getdefaultview(employees);                     application.current.dispatcher.begininvoke(new action(() => {                         datagrid.itemssource = filteredview;                         testlabel.content = "who's " + i;                         i++;                     }));                 },                 null, //no object callback parameter                 timespan.fromseconds(0), //start in x millisec                 timespan.fromseconds(1)); //time between call         } 

you can use backgroundworker, hook .completed , there render (using

backgroundwoker worker = new backgroundworker(); worker.dowork += functiotodo worker.completed += functionwhere update ui worker.runasynchronous(); //actually starts thread 

in function updates ui don't forget use dispatcher access ui thread:

dispatcher.invoke((action) delegate { here code}) 

to access ui thread elsewhere.

other cooler approach take care of propertychanged , bind changes ui. bit more complex , don't know details head.

you can use timer start whole thing every few seconds.

a third approach have trigger when update data base. need more details know how attach there. there can call updates in ui , don't need use cpu check every seconds (you know, work interruption instead of polling).


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -