线程中操作window控件无效!

最近做c/s架构,大部分用到多线程,遇到了在线程执行中无法操作控件,网上搜来一些方法。
定义个委托:
1delegate void SetTextCallback(string text);
2

线程执行的代码:
 1public void SendAlarm(object state)
 2        {
 3            string xmlString = XmlStructor.GetTFMXml(ct);
 4            if (this.textBox1.InvokeRequired)
 5            {
 6                SetTextCallback s = new SetTextCallback(setText);
 7                this.Invoke(s,xmlString);
 8            }

 9            msgclass.Send(xmlString);
10        }
操作控件:
1/// <summary>
2        /// 测试
3        /// </summary>
4        /// <param name="x"></param>

5        public void setText(string x)
6        {
7            textBox1.Text += (x + "\r\n\r\n\r\n\r\n");
8        }
原文地址:https://www.cnblogs.com/jinweida/p/1160625.html