c# - How can i use a timer in synchronization with background worker? -
i using background worker in application data hardware , updating in ui continuously. need configure hardware info it. here requirement change configuration of hardware every 2 sec , need update corresponding info in ui. how can achieve proper synchronization?
edit: here posting logic:
worker3.workerreportsprogress = true; worker3.workersupportscancellation = true; worker3.dowork += new doworkeventhandler(worker3_dowork); worker3.progresschanged += new progresschangedeventhandler(worker3_processchanged); dispatchertimer timer = new dispatchertimer(); private void button_click_1(object sender, routedeventargs e) { timer.interval = timespan.fromseconds(5); timer.tick += timer_tick; timer.start(); worker3.runworkerasync(); } private void worker3_dowork(object sender, doworkeventargs e) { // here running infinite loop. in loop // calling function in dll data harware. passing info got process changed event } private void worker3_processchanged(object sender, progresschangedeventargs e) { // here updating ui information got hardware. } private void time_tick(object sender, eventargs ) { if(worker3.isbusy==true) worker3.cancelasync(); // configuring hardware new options. // again start background worker if(worker3.isbusy!=true) worker3.runasync(); }
Comments
Post a Comment