Thread thread = new Thread(new ThreadStart(Receive));
// 我也用过这个Thread thread = new Thread(new ParameterThreadStart(Receive));也不行。
thread.Start();Private void Receive()
{
    textBox1.text = "aaa"; // 它老是在这里报错,说不能什么通过线程访问什么
//Cross thread operation not valid: Control "textBox1" accessed from a thread other than the thread it was created on.
}望高手指点

解决方案 »

  1.   

    哦,弄聊天程序的时候碰到过,换成STATUSBAR/strip控件就冒事了!
      

  2.   

    delegate void SetTextCallback(string text);
    private void SetText(string text)
    {
                 if (textBox1.InvokeRequired)
                {
                    AddListBoxTextCallback d = new AddListBoxTextCallback(SetText);
                    this.Invoke(d, new object[] { text });
                }
                else
                {
                    textBox1.text   =   text;   
                }
            }
    你的程序改为
    Private   void   Receive() 

            SetText(string text)="aaa");   //   它老是在这里报错,说不能什么通过线程访问什么 
    //Cross   thread   operation   not   valid:   Control   "textBox1"   accessed   from   a   thread   other   than   the   thread   it   was   created   on. 

      

  3.   

    AddListBoxTextCallback   d   =   new   AddListBoxTextCallback(SetText); 
    应为SetTextCallbac d=new SetTextCallbac(setText)
      

  4.   

    不能在辅助线程中直接操作WinForm界面控件。但是可以通过委托实现。delegate void UpdateTextBoxHandle(string value)private void SetTextBox(string value)
    {
        textBox1.text   =   value;
    }// 定义委托
    UpdateTextBoxHandle updateInThread = new UpdateTextBoxHandle(SetTextBox);Private   void   Receive() 
    {
    // 通过委托刷新 
        updateInThread("aaa");
    }你试试看行不行
      

  5.   

    使用BeginInvoke 
    public delegate void InvokeDelegate();private void Invoke_Click(object sender, EventArgs e)
    {
       myTextBox.BeginInvoke(new InvokeDelegate(InvokeMethod));
    }
    public void InvokeMethod()
    {
       myTextBox.Text = "Executed the given delegate";
    }
      

  6.   

    在form_load里写上:
    CheckForIllegalCrossThreadCalls = false;PS:1楼湖南人啊?
      

  7.   

    这是因为2005加入了安全线程的机制 你的代码在2003里就没问题了
    可以手动关闭次功能CheckForIllegalCrossThreadCalls   =   false; 
      

  8.   

    Window窗体主线程和当前线程的安全考虑,在vs2003里是没问题的.
    2楼和5楼是安全的方法.