求问非UI线程批改UI的标准方法
求问非UI线程修改UI的标准方法
我们知道不是创建控件的线程无法直接访问控件,那么有没有一个现代的、标准的方法实现非UI线程修改UI控件?
谢谢!
------解决方案--------------------
this.Invoke(new Action(() => { textBox1.Text = s; }));
------解决方案--------------------
SynchronizationContext.Post
------解决方案--------------------
再完善一下:
我们知道不是创建控件的线程无法直接访问控件,那么有没有一个现代的、标准的方法实现非UI线程修改UI控件?
谢谢!
------解决方案--------------------
this.Invoke(new Action(() => { textBox1.Text = s; }));
------解决方案--------------------
SynchronizationContext.Post
------解决方案--------------------
再完善一下:
public void UpdateText(string text)
{
Action action = () => { textBox1.Text = text};
if (this.InvokeRequired) this.Invoke(action);
else action();
}