多線程操作窗體控件

delegate void SetTextCallback(string text);<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

          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());

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章