2012-07-16 2 views
-2
Thread main; 

    public void bomb() 
    { 
     string link = textBox1.Text; 


     for (int i = 0; i <= richTextBox1.Lines.Length; i++) 
     { 
      HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + link + "/"); 
      WebProxy myproxy = new WebProxy(this.richTextBox1.Lines[i], false); 
      //request.Proxy = myproxy; 
      request.Method = "GET"; 
      HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
      label1.Invoke((MethodInvoker)delegate { label1.Text = i.ToString(); }); 
     } 


    } 

    private void button1_Click(object sender, EventArgs e) 
    { 

     main = new Thread(bomb); 
     main.Start(); 

    } 

그러나 라인 액세스를 얻을 수 없습니다 richTextBox1.Lines.Length 및 richTextBox1.Lines을 [I]스레드는 RichTextBox.Lines에

생성 오류 :

Cross-thread operation not valid: Control 'richTextBox1' accessed from a thread other than >the thread it was created on.

하는 경우 richtextbox에서 텍스트를 가져오고 싶습니다만 괜찮습니다.하지만 라인을 얻고 싶으면 에러가납니다.

감사합니다.

답변

1

사용 Invoke 당신이처럼 richTextBox1.Lines에 액세스 할 수는 label1

var lines = (string[])richTextBox1.Invoke(
          (Func<string[]>)(() => this.richTextBox1.Lines)); 

동일은 textBox1

위해도 마찬가지입니다