private void test(string code) { string text = code + "\n\n"; string a = RecvTextBox.Text; if (RecvTextBox.InvokeRequired) {//c#中禁止跨线程直接访问控件,InvokeRequired是为了解决这个问题而产生的,用一个异步执行委托 RecvTextBox.BeginInvoke(new MethodInvoker(delegate { RecvTextBox.AppendText(text); })); } else { RecvTextBox.AppendText(text); } }
private void test1(string code, bool flag) { string text = code + "\n\n"; string a = RecvTextBox.Text; if (RecvTextBox.InvokeRequired) {//c#中禁止跨线程直接访问控件,InvokeRequired是为了解决这个问题而产生的,用一个异步执行委托 RecvTextBox.BeginInvoke(new MethodInvoker(delegate { RecvTextBox.AppendText(text); })); } else { RecvTextBox.AppendText(text); } if (!flag) { TcpClientMgr.GetInstance().Close(); } }
/// <summary> /// ScrollToEnd /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RecvTextBox_TextChanged(object sender, TextChangedEventArgs e) { RecvTextBox.ScrollToEnd(); }