C# 关于跨线程调用资源(调用控件)
/// <summary>
/// 往日志的文本框上追加数据
/// C# 关于跨线程调用资源(调用控件)
/// </summary>
/// <param name="txt"></param>
public void AppendTextToTxtLog(string txt)
{
if (richTextBox1.InvokeRequired)//判断调用该控件是否属于跨线程调用
{
richTextBox1.Invoke(new Action<string>(s =>
{
this.richTextBox1.Text = string.Format("{0}\r\n{1}", s, richTextBox1.Text);
}), txt);
}
else
{
this.richTextBox1.Text = string.Format("{0}\r\n{1}", txt, richTextBox1.Text);
}
}