How to update UI from child tasks in WinForms

前端 未结 2 1741
心在旅途
心在旅途 2020-12-17 15:41

I\'ve got a simple little winforms app that performs a long running process on another thread via a TPL Task. During this long running process I\'d like to update the UI (t

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-17 16:11

    Yes, you can explicitly call BeginInvoke on the Window/Control that you want to communicate with. In your case this would look like this:

    this.textBox.BeginInvoke(new Action(() =>
    {
       this.textBox.Text = "From child task.";
    }));
    

提交回复
热议问题