项目有一个需求,在线程中给控件赋值报错了
百度后需要托管
delegate void RichTextBoxItem(string sRes);
public void AddItemRichTB(String sRes)
{
if (this.richTextBox1.InvokeRequired)
{
RichTextBoxItem r = new RichTextBoxItem(AddItemRichTB);
this.Invoke(r, new object[] { sRes });
}
else
{
richTextBox1.Text = sRes;
}
}
void Thr()
{
while(true)
{
...
AddItemRichTB("Foder Not Exist");
...
}
}