线程中访问控件

记录一下一个比较通用的做法 线程中访问控件。

        private delegate void SetWebBorswerText(string value);
        private void SetValue(string value)
        {
            if (this.InvokeRequired)
            {
                SetWebBorswerText d = new SetWebBorswerText(SetValue);
                object arg = (object)value;
                this.Invoke(d, arg);
            }
            else
            {
                this.webBrowser1.DocumentText = value;
            }
        }

        private delegate string GetTextHandle(TextBox control);
        private string GetText(TextBox control)
        {
            if (this.InvokeRequired)
            {
                return (string)this.Invoke(new GetTextHandle(this.GetText), control);
            }
            else
            {
                return ((TextBox)control).Text;
            }
        }
原文地址:https://www.cnblogs.com/wonderfuly/p/2650859.html