.net - Exception when change Border property from other thread -


i've component in wpf, component use border , use border background property change background color of entire component.

the problem, when try alternate between 2 different colors, timer, invalidoperationexception thrown. "the calling thread cannot access object because different thread owns it". on timer method put code change border properties in dispatcher object.

            mainborder.dispatcher.begininvoke((threadstart)delegate()              {                 mainborder.borderbrush = mybrush;                mainborder.background = mybrush;             }, null); 

but exception thrown , not understand doing wrong! example in same time doing code

lbholderservico.dispatcher.begininvoke((threadstart)delegate() {     lbholderservico.foreground = new solidcolorbrush(holdlabelsfontcolor); }, null); 

to change label font color , works fine.

thanks , regards

an alternative define brushes/animations resources , start animations or assign brushes when needed.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -