110,499
社区成员
发帖
与我相关
我的任务
分享
ThreadStart start = new ThreadStart(DoSomething1);
Thread thread = new Thread(start);
thread.Start();
private void DoSomething()
{
//耗时操作
//在另外一个线程不能直接调用主线程的控件,这么写
setTextSafe(this.TextBox1, "abc");
}
private delegate void setValue(TextBox ctrl, object value);
private void setTextSafe(TextBox ctrl, object value)
{
if (this.InvokeRequired)
{
this.Invoke(new setValue(setTextSafe), ctrl, value);
}
else
{
ctrl.AppendText((string)value);
}
}
源文档 <http://topic.csdn.net/u/20101201/13/1a79b735-1acb-4569-a03a-5cfd7b7cff8e.html?58254>
}