if (this.textBox1.InvokeRequired)//如果调用控件的线程和创建创建控件的线程不是同一个则为True { while (!this.textBox1.IsHandleCreated) { //解决窗体关闭时出现“访问已释放句柄“的异常 if (this.textBox1.Disposing || this.textBox1.IsDisposed) return; } this.Invoke(new Action<string>(delegate (string a) { textBox1.Text = s; }), s); } else { this.textBox1.Text = s; }
使用的时候最好加上异常捕获 private void SetText(string text) { try { if (textBox1.InvokeRequired) { this.Invoke(new Action(() => { textBox1.Text = text; })); } else { textBox1.Text = text; } } catch { } }
来源:U5网赚博客(QQ/微信:313919848),转载请保留出处和链接!
本文链接: https://www.u5fuye.com/post/3166
下一篇:JS 类的使用
相关阅读:
本文暂时没有评论,来添加一个吧(●'◡'●)