"how to access c# wpf control in thread safe way?" Code Answer


you simply want to use the dispatcher.invoke method (or the asynchronous equivalent dispatcher.begininvoke), which will marshal the call to the main wpf ui thread.

the dependencyobject class contains a dispatcher property, which means all controls and other objects which inherit from this class also provide this property, in a way similar to winforms. in addition, the application object provides access to the dispatcher.

an example usage might be the following (in code-behind of a window/usercontrol):

this.dispatcher.invoke((action)(() =>
By Vyacheslav Gerasimov on September 27 2022

Answers related to “how to access c# wpf control in thread safe way?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.