.net System.Threading.Timer needs to access Silverlight 3 UI component in callback -
i have silverlight 3 page. use system.threading.timer perform asynchronous wcf service call. make call passing in silverlight page class ("this") in "state" object in timer constructor, , accessing service client proxy through it. doing way, callback wcf service fires fine.
my problem (as understand it) return wcf call occurs in separate thread, , access error when attempt access/modify ui elements on silverlight page.
first, understanding of problem correct?
second, architucturally correct method of solving problem?
thank assistance.
using this.dispatcher.begininvoke
necessary move code execution on thread has access ui elements. thought may worth applying. may easy this:-
this.dispatcher.begininvoke(() => { // whole body of code needed });
however there couple of things consider. if whole bunch code going significant work doesn't involve access ui elements may better first switch ui thread when you've got modify ui. may mean changing order things happen, perhaps employing few variables hold onto values until later.
secondly if same call used ui thread may better re-arrange code code these callbacks run code straight out use of seondary function call or begininvoke. dispatchers checkaccess
method can determine whether begininvoke needed. in specific scenario begininvoke allways needed.
Comments
Post a Comment