110,570
社区成员
发帖
与我相关
我的任务
分享
public delegate void myDelegate(string strText);
//调用线程的方法
private void button4_Click(object sender, EventArgs e)
{
Thread th = new Thread(new ParameterizedThreadStart(RunLoop));
th.Start(10);
th.Name = "ForegroundThread";
}
//线程方法
public void RunLoop(object iMax)
{
String threadName = Thread.CurrentThread.Name;
for (int i = 0; i < Convert.ToInt32(iMax); i++)
{
textBox1.Invoke(new myDelegate(txtText), new Object[] { threadName + " count: " + i.ToString() });
}
}
//操作窗体控件的方法
public void txtText(string strText)
{
textBox1.Text += strText + "\r\n";
textBox2.Text = "1"; //困惑这一句,上面是textBox1.Invoke()调用的这个方法,这里操作textBox2控件
}