winform 后台线程更新UI

 //后台线程更新TextBox
 private void SetTextBox(TextBox txt, string value)
        {
            Action act = () =>
                {
                    txt.Text = value;
                };
            if (txt.InvokeRequired)
            {
                txt.Invoke(act);
            }
            else
            {
                act();
            }
        }

 private void TestThread()
        {
            int i = 0;
            while (true)
            {
                Thread.Sleep(1000);
                i++;
                SetTextBox(textBox2,i.ToString());
            }
        }

  

原文地址:https://www.cnblogs.com/KQNLL/p/5213965.html