WPF 跨线程修改前台控件

场景:

Public Class A
{
  Thread thd;
  public A()
  {
     thd=new Thread(new ThreadStart(Demo));
     thd.IsBackground=true;
     thd.Start();
 }


  public Static void Demo()
  {
   UI _UI=new UI();
   _UI.tb.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,new Action()=>{
   _UI.tb.Text="我是描述控件!";
   });
}

项目中的UI控件:

public Class UI:UserControl
{
  Public TextBlock tb=new TextBlock();
  public UI()
     {
   InitializeComponent();
       this.AddChild(tb);
     }
} 

原文地址:https://www.cnblogs.com/GeneralKING/p/2771965.html