winforms - C# Synchronisation with screen updates -


i have following problem: application screen-update , should make screenshot of new view after that.
code follows:

    public viewmodelbase screen {         {             if (_screen == null) {                 screen = new datasourcechooserscreenviewmodel(this);                 history.changehistory(add_item);             }             return _screen;         }         set {             _screen = value;             onpropertychanged("screen");              system.windows.forms.application.doevents();         }     } 

the screen update done in "onpropertychanged("screen")" , screenshot taken in "history.changehistory(add_item)".
methods calling setter "screen" follow same scheme:

//do screen = otherscreen; history.changehistory(add_item); //do else 

and here's problem: screenshot made before screen has been updated although execution order says else.

to solve problem myself tried several things:
busy waiting in add_item
waiting timer in add_item
usage of asynchronous threading waiting on propertychangedevent via begininvoke() , endinvoke()
usage of system.windows.forms.application.doevents()

all tries had same result: screenshots done before screen became updated. in attempt usage of timers figured out, screen becomes updated after add_item performed. suggest compiler makes implicit threading , don't know how fix/prevent it.

thanks help.

when have that, use timer event fire after processed. one-shot timer event , usage this:

to fire it:

timer t=new timer(); t.tick+=doafter; t.interval=100; t.start(); 

what needs done here:

void doafter(object sender, someargs a) {     timer t=(timer)sender;     t.stop();     t.dispose();     //  perform stuff here     dostuff(); } 

that way have chance message loop , screen updates finish before timer fires.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -