Dispatcher Currently, only the non-user interface (UI) threads can be run on the UI.Code.
You can useDependencyobject.DispatcherAndScriptobject.DispatcherAttribute to access the UI threadDispatcherObject. These methods are instance methods, but these types of instances cannot be accessed frequently from non-UI threads. However, this applicationProgramOfDeploymentThe object isDependencyobjectAnd it canCurrentAttribute is used by any thread.
You can callCheckaccessMethod to Determine whether the caller is in the UI thread. If the caller is not in the UI thread, you can callBegininvokeTo run the specified delegate on the UI thread.
private delegate void addtextdelegate (Panel P, string text); Private void addtext (Panel P, string text) {P. children. clear (); p. children. add (New textblock {text = text});} private void testbegininvokewithparameters (Panel p) {If (P. dispatcher. checkaccess () addtext (P, "added directly. "); else p. dispatcher. begininvoke (New addtextdelegate (addtext), P, "added by dispatcher. ") ;}