Sunday 15 March 2015

c# - wpf not refresh code if not focused -



c# - wpf not refresh code if not focused -

i have situation: class contains background worker thing in while cycle:

public class ccontrols { public delegate void controlchangedeventhandler(); public event controlchangedeventhandler controlchangedevent; private readonly backgroundworker worker; bool bclose = false; public ccontrols(intptr hwnd) { worker = new backgroundworker(); worker.dowork += worker_dowork; worker.runworkercompleted += worker_runworkercompleted; } void worker_runworkercompleted(object sender, runworkercompletedeventargs e) { bclose = true; } public void enable(bool benable) { if (benable && !worker.isbusy) { worker.runworkerasync(); } else { bclose = true; } } void worker_dowork(object sender, doworkeventargs e) { while (!bclose) { // job // .............................................. // if (controlchangedevent != null) { controlchangedevent(); } } } }

i have form create instance of class , set listener of controlchangedevent:

ccontrols ct = new ccontrols(); ct.controlchangedevent += ct_controlchangedevent; int changes = 0; void ct_controlchangedevent() { dispatcher.invoke(dispatcherpriority.background, (action)delegate { changes ++; infolabel.content = string.format("changes: {0}", changes); }); }

but infolabel changes if programme have focus, otherwise not fired...

any ideas? ;)

c# wpf visual-studio-2012 focus backgroundworker

No comments:

Post a Comment