在textbox中是显示
delegate void ShowDelegate(string str);
private void ReceiveData(Session session, StringRequestInfo requestInfo)
{
ShowDelegate del = new ShowDelegate(show);
// del.Invoke(requestInfo.Body); /方法1 这个无法跨线程
//Invoke(del, requestInfo.Body); //可以跨线程
this.Invoke(del, requestInfo.Body); //可以跨线程
textBox1.Invoke(new System.EventHandler(show1), requestInfo.Body);//可以跨线程
}
private void show(string str)
{
textBox1.Text += str + "\n";
}
private void show1(object o, System.EventArgs e)
{
textBox1.Text += o.ToString()+"\n";
}
试下来,第一种delegate.invoke()无法跨线程