多线程操作窗体控件

来源:互联网 发布:日本爱知大学 编辑:程序博客网 时间:2024/05/22 09:44

delegate void SetTextCallback(string text);

          private void SetText(string text)

          {

              // InvokeRequired required compares the thread ID of the

              // calling thread to the thread ID of the creating thread.

              // If these threads are different, it returns true.

              if (this.textBox1.InvokeRequired)

              {

                  SetTextCallback d = new SetTextCallback(SetText);

                  this.Invoke(d, new object[] { text });

              }

              else

              {

                  this.textBox1.Text = text;

              }

          }

 

SetText(time.ToString());

原创粉丝点击